A Travis CI compatible unit testing architecture for WordPress plugins that use WordPress core's official unit-testing framework and PHPUnit
- Automatically fires after every commit (or you can specify certain branches)
- Downloads and sets up multiple versions of WordPress and PHP (as many as you want to specify)
- Runs all the tests and e-mails you on failure
- You have a WordPress plugin in GitHub (and thus a GitHub account)
- You posses basic knowledge of how to add and edit files using git
- Place
.travis.yml
file in your plugin's root folder (you may want to customize your build settings here) - Create a subfolder of your plugin called
tests/
and copy over thebootstrap.php
andphpunit.xml
files from this repo'stest/
folder - Customize the newly copied
/tests/bootstrap.php
with the path to your plugin file - Activate Travis CI for your plugin
- Add tests to the
tests/
folder following the instructions below
- Check out the test suite locally:
cd /path/to/your-plugin/
svn co http://unit-tests.svn.wordpress.org/trunk/includes/ tests/lib
-
Set up a
wp-tests-config.php
file inside thetests
directory. (sample) -
Run the tests:
cd /path/to/your-plugin/tests
phpunit
- Each test file should live in the
tests/
folder and should be named in the format oftest_{name_of_test}.php
. - Each test file should contain a single class named in the form of
WP_Test_{name_of_test}
that extendsWP_UnitTestCase
. - Example Tests: WP Document Revisions
There's a separate branch setup
which contains setup and config files which are pulled down on the fly when testing.
- Fork the project to your account, make changes, and submit a pull request
- Integrate with your plugin and open issues / feature requests as you see fit
- 2012-09-15 - Removed
wordpress-tests
submodule in favor of core's SVN. - 2012-04-16 - Initial commit of skeleton based off of (legacy) core testing framework.
- 2012-06-30 - Complete rewrite to rely on newer wordpress-tests framework and better PHPUnit integration.
Special thanks to @johnpbloch and @scribu for doing much of the legwork on the rewrite.