The Pressbooks unit testing framework was built (then slightly tweaked) using WP-CLI. The tests run automatically on commit via Travis-CI, with more in-depth reporting via Codecov.

To run the tests locally, do:

bash cd /path/to/wordpress/wp-content/plugins/pressbook bash bin/install-wp-tests.sh wordpress_test DBUSER DBPASS localhost latest phpunit

  • Replace /path/to with your path.
  • wordpress_test is the name of a new test database (all data will be deleted!)
  • DBUSER is your MySQL user name
  • DBPASS is your MySQL user password
  • localhost is your MySQL host
  • latest is the WordPress version; could also be 4.5, 4.6 etc.
  • PHPUnit is installed….

The bash script installs a copy of WordPress and the WordPress unit testing tools in/tmp. It then creates a new tests database to be used while running tests. The bash script can be run multiple times without errors, but it will not overwrite previously existing files.

Tests are in /tests/*.*

Tests cover the code in /includes/*.*

Please help us improve code coverage!

More info: