Is there any examples of using PHP unit tests with WordPress themes, seems a lot of blogs out there on the subject are out dated as the core unit tests are apart of trac, yet last night – I pulled trac and tried to set up a sample theme to run tests on. It doesn’t quiet work, you have to run all the tests to test your theme and even if you try and require a file – it tries to require it before WordPress is instantiated and it becomes a giant mess.
Any ways, I know there’s the plugin for theme unit testing – but that just installs a ton of posts that “try” and break your theme – doesn’t test the underlying logic – especially if building a framework – php unit is best here as you can test out all the different options and implementations of your code.
So is there any way to run PHPunit inside a theme?
When it comes to unit testing themes, it’s a small jungle. I read on Make WordPress Core that things are changing (http://make.wordpress.org/core/2013/08/06/a-new-frontier-for-core-development/).
I searched for blogs linking to that specific post in hope to find some useful. Found this: http://ben.lobaugh.net/blog/84669/how-to-add-unit-testing-and-continuous-integration-to-your-wordpress-plugin that looks promising. Note that it focuses on plugin testing, but useful for theme unit testing also.
I’m gonna set up a specific enviroment this week (if nothing comes in between) and do a hands on tutorial for Unit testing themes (gonna try different methods).
Slightly off topic (or as a bonus), when i test themes, the tools i use for testing are the following:
All plugins are listed on the WordPress.org Plugin Repo.