Unit Testing
The Pressbooks unit testing framework was built with WP-CLI. The tests run automatically on commit via GitHub Actions, with more in-depth reporting via Codecov.
To run the tests locally, make sure PHPUnit is installed, then do:
cd /path/to/wordpress/wp-content/plugins/pressbooks 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 nameDBPASS
is your MySQL user passwordlocalhost
is your MySQL hostlatest
is the WordPress version; could also be5.7
,5.9.3
etc.
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 /inc/*.*
Please help us improve code coverage!