Body: <p>I would like to know if there is a way unit test templates using Craft 2.5? For example trying to prevent null pointers happening in production when an image is remove from the entry</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-27T23:16:25.200Z
Comments.Text: I'm not sure how you would unit test templates, probably it could be done, but you might be better served by coding defensively, as per [Handling Errors Gracefully in Craft CMS](https://nystudio107.com/blog/handling-errors-gracefully-in-craft-cms#what-it-means-to-code-defensively)
Comments.UserDisplayName: andrew.welch
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-28T04:45:03.300Z
Comments.Text: I'll second [Andrew's](https://craftcms.stackexchange.com/questions/28564/what-the-best-strategy-to-test-craft-template#comment37158_28564) suggestion as a better approach.  Outside of that, the front-end templates of a site are generally tested with acceptance or integration testing instead of unit testing.
Comments.UserDisplayName: Brad Bell
Tags: <templating><tests>
Title: What the best strategy to test Craft template?
ThreadText: # What the best strategy to test Craft template?
  
  (Asked by: username_0 on 2018-11-27)
  
  I would like to know if there is a way unit test templates using Craft 2.5? For example trying to prevent null pointers happening in production when an image is remove from the entry
  
  **Tags:** templating, tests
  
  > **Comments:**
  > **username_1**: I'm not sure how you would unit test templates, probably it could be done, but you might be better served by coding defensively, as per [Handling Errors Gracefully in Craft CMS](https://nystudio107.com/blog/handling-errors-gracefully-in-craft-cms#what-it-means-to-code-defensively)  
  > **username_2**: I'll second [Andrew's](https://craftcms.stackexchange.com/questions/28564/what-the-best-strategy-to-test-craft-template#comment37158_28564) suggestion as a better approach.  Outside of that, the front-end templates of a site are generally tested with acceptance or integration testing instead of unit testing.  
  
  ---
  
  ## 0 answers
  
  