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?

1 Answer 1


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.

  • Developer (Set of tools for developers. When activating the plugin, you will be promted for what kind of development you are working on and a list of installable recomended plugins.)
  • Debug Bar (Developer Recomended plugin)
  • Debug Bar Extender (Developer Recomended plugin)
  • Rewrite Rules Inspector (Developer Recomended plugin)
  • Log Deprecated Notices (Developer Recomended plugin. This one i use a lot!)
  • Regenerate Thumbnails (Developer Recomended plugin)
  • Theme Check (Developer Recomended plugin. This one i use a lot!)
  • ThemeForest-Check (While i don't sell things at that place, the theme check is pretty good to my surprise. Note. You need Theme Check Plugin installed)
  • Theme Mentor (Getting deeper into the code analysis of the themes).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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