Unit Tests
Setup testing environment
In the theme root within your environment (localWP: "Open site shell" option) run:
<db-name>
is the name of the db you want the run the tests in. We suggest creating a separate db form your dev db for testing.<db-user>
Database username<db-pass>
Database password[db-host]
Database url and port. For localWP get the port from the url when opening Adminer.
Note for localWP on linux the command looks like this for localWP:
./tests/install-wp-tests.sh local-test root root localhost:10063
Notes:
On localWP, make sure you are running from the "Open site shell" menu option, so the environment is loaded
On localWP, remove
--protocal=tcp
on line #141 of ./tests/install-wp-tests.shOn localWP, you can get the database port from the browser url after opening adminer
You may need to install svn:
sudo apt install subversion
If you get an error that looks like:
Could not find /{path}/wordpress-tests-lib /includes/functions.php, have you run tests/install-wp-tests.sh ?
delete the temp folder and run the install again.
Running the tests
Install phpunit and phpunit-polyfills form the theme root.
Run ./vendor/bin/phpunit
The tests need phpunit v7. v8 and above currently don't work.
Writing tests
tests are located in the theme ./tests folder
unit test files need to start with 'unit-test'
unit test function need to start with 'test_'
phpunit documentation https://phpunit.readthedocs.io/en/7.5
Last updated