A Travis CI compatible unit testing architecture for WordPress plugins that use WordPress core's official unit-testing framework and PHPUnit
Update: Use WP-CLI to create all these files automatically. See http://wp-cli.org/blog/plugin-unit-tests.html
- 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.ymlfile 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.phpandphpunit.xmlfiles from this repo'stest/folder - Customize the newly copied
/tests/bootstrap.phpwith the path to your plugin file - Set up the tests library as a submodule:
git submodule add git://github.com/scribu/wp-tests-lib.git tests/lib - Activate Travis CI for your plugin
- Add tests to the
tests/folder following the instructions below
All you need to do is set up a wp-tests-config.php file inside the tests directory. (sample)
Then, 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
- 2013-01-19 - Mandate plugins have wp-tests-lib as a submodule.
- 2012-09-15 - Removed
wordpress-testssubmodule 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.