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();
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.
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.
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?
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.