# Unit Testing Kirby

**URL:** <https://forum.getkirby.com/t/unit-testing-kirby/5215>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 9, 2016, 9:51pm UTC](https://forum.getkirby.com/t/unit-testing-kirby/5215 "2016-09-09T21:51:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LCD344](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LCD344](https://forum.getkirby.com/u/LCD344)\
**Post date:** [September 9, 2016, 9:51pm UTC](https://forum.getkirby.com/t/unit-testing-kirby/5215/1 "2016-09-09T21:51:06Z")

</div>

This isn’t exactly a solution or suggestion or a community topic… so I Wasn’t sure where to put it, hence general!

So… does anyone in the community uses unit testing while developing kirby?  
I got newly into unit testing, and so decided to see if anyone has good tips for it.

I’m working on a plugin that is going to be pretty extensive, and I decided to do it TDD. The main problem I encountered is getting everything to bootstrap for the tests. for now what I’m doing is set up and launch kirby before (in a setup method).

```
   $kirby = kirby();
   $kirby->launch();

```

Also I included the kirby bootstrap as a bootstrap files… anyone else with experience with this?

Ok, I realize this came out as a question 🙂 but I’m also interested to hear in general about what you think of unit testing, and unit testing with kirby.

cheers!

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 10, 2016, 9:24am UTC](https://forum.getkirby.com/t/unit-testing-kirby/5215/2 "2016-09-10T09:24:18Z")

</div>

Unit testing means that you test each unit separately. If you load Kirby and try to test the behavior, it’s not really unit testing anymore (it’s also very hard to do as you can’t control what Kirby does internally).

I’d use so-called mock objects to replicate the Kirby features your plugin uses. Those mock classes can then be controlled by you to return specific values in specific situations to test different behaviors of your plugin.

Of course you can still load the Kirby bootstrap file to get access to the Toolkit classes etc. You don’t need to mock those, but you should mock the complex classes.

---

<div class="post-metadata">

**Author:** ![LCD344](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LCD344](https://forum.getkirby.com/u/LCD344)\
**Post date:** [September 10, 2016, 2:11pm UTC](https://forum.getkirby.com/t/unit-testing-kirby/5215/3 "2016-09-10T14:11:58Z")

</div>

Thanks for the recommendations!  
I’m using it for is to test plugin functionality, which is still unit testing.  
But then I guess to test more complex kirby functionality I’d do integration testing? (Sorry I’m new to the testing world.) do you have any recommendations for this?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 10, 2016, 2:17pm UTC](https://forum.getkirby.com/t/unit-testing-kirby/5215/4 "2016-09-10T14:17:47Z")

</div>

Yes, that would be integration testing. To be honest, I haven’t yet integration-tested a Kirby plugin as those tests are very hard to get right. Depending on the parts of Kirby your plugin uses, you’d need a separate testing content directory etc., but it would be possible.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:55pm UTC](https://forum.getkirby.com/t/unit-testing-kirby/5215/5 "2025-02-06T16:55:18Z")

</div>

Archived on February 6, 2025, 4:55pm UTC


