Given how WordPress is written and how it interacts with a database and given how its not very much OOP oriented, is there a way to unit test a theme? is there a way unit test a framework (not a theme framework) that interacts with WordPress, that is, for example, can you write a unit test for dealing with the loop, dealing with the widgets?

If so does any one have any examples? I know how to write unit tests, but I have never tried to write one for a theme.



There is nothing stopping you from writing your own unit testing for themes/plugins using PHPUnit or some other testing platform.

As for WordPress, it has an official Unit Tests here:

There are several build scripts that can automate unit testing found here, including WP-CLI that have built in unit testing, though you have to obviously write your own code.

I also found this plugin today via scibu's twitter rant :)
There are a few more in the repo:

Also check out this: Tutorials for Unit-Testing in WordPress and for unit-test.svn.wordpress.org?


I wrote the Travis-CI powered PHPunit testing library for Jigoshop and Easy Digital Downloads both of which are Ecommerce WP plugins developed on Github. The library employed could be easily converted to work for themes. The nice thing about the Travis-CI powered suite is that we can use it to quickly test multiple PHP and WP versions. If you're theme is a premium theme, and thus putting it on a free Github repo isn't an option, the suite works on Private Github repos with Travis-CI.

Alternatively, you can use the one found in Jigoshop and use commandline powered PHPUnit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.