<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>

CC BY-SA 4.0
2018-11-27T23:16:25.200Z
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)
andrew.welch
CC BY-SA 4.0
2018-11-28T04:45:03.300Z
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.
Brad Bell
<templating><tests>
What the best strategy to test Craft template?
# 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

