<p>There is a good example of testing with PHPUnit in a Craft plugin here: <a href="https://github.com/selvinortiz/craft.loath" rel="nofollow">https://github.com/selvinortiz/craft.loath</a> and an example on how to stub out the global <code>craft()</code> class here: <a href="https://craftcms.stackexchange.com/questions/10049/stub-out-the-global-craft-object-for-phpunit-tests">Stub out the global craft() object for PHPUnit tests</a></p>

<p>Note that testing in Craft should be a lot easier/convenient in the upcoming Craft 3.</p>

CC BY-SA 3.0
2016-08-12T12:30:58.483Z
In the upcoming Craft 3, it would be great if there came a section where Craft 3 and PHPUnit had a nice tutorial for beginners to write good plugins?

Anyway thanks for the answer!
Bram B
CC BY-SA 3.0
2016-08-11T17:04:38.837Z
2016-08-11T17:04:38.837Z
Brad Bell
<p>Is it possible to implement PHPUnit into Craft CMS? If so, where can I find a good explanation or tutorial? I already tried a Github link for a plugin (testing the plugin).</p>

<p>But I am new to both but really want to TDD the plugins. Any example pages or a quick guide would be great!</p>

<plugin-development>
PHPUnit testing for Craft plugins or controllers
# PHPUnit testing for Craft plugins or controllers

(Asked by: username_0 on 2016-08-11)

Is it possible to implement PHPUnit into Craft CMS? If so, where can I find a good explanation or tutorial? I already tried a Github link for a plugin (testing the plugin).

But I am new to both but really want to TDD the plugins. Any example pages or a quick guide would be great!

**Tags:** plugin-development


---

## 1 answers

### Answer by username_1 on 2016-08-11. Score: 3 | Accepted answer

There is a good example of testing with PHPUnit in a Craft plugin here: <https://github.com/selvinortiz/craft.loath> and an example on how to stub out the global `craft()` class here: [Stub out the global craft() object for PHPUnit tests](https://craftcms.stackexchange.com/questions/10049/stub-out-the-global-craft-object-for-phpunit-tests)

Note that testing in Craft should be a lot easier/convenient in the upcoming Craft 3.

> **Comments:**
> **username_0**: In the upcoming Craft 3, it would be great if there came a section where Craft 3 and PHPUnit had a nice tutorial for beginners to write good plugins?  Anyway thanks for the answer!  

---

