There are a few automated PHPUnit tests and Selenium UI tests included with the plugins. Below we will lay out the steps necessary to run the tests.
We recommend the use of a pre-configured virtualized environment, like Varying Vagrant Vagrants (VVV), as it provides a consistent environment for developing, testing, troubleshooting and debugging your code. VVV includes WP-CLI and PHPUnit which make unit testing that much easier.
If you're using VVV you can skip step 1.
- Install WP-CLI and PHPUnit
- Initialize the unit tests using WP-CLI
- In a terminal, navigate to the root of the WordPress instance and run
wp scaffold plugin-tests plugin-namereplacingplugin-namewith the name of the plugin. So, for the Widgets Bundle you would runwp scaffold plugin-tests so-widgets-bundle.
- Navigate to the root of the plugin directory.
cd wp-content/plugins/so-widgets-bundleand runbash bin/install-wp-tests.sh wordpress_test db_user db_password localhost latest, replacingdb_useranddb_passwith your database user's username and password andlocalhostwith your database hostname. - That's it! Now you can run
phpunitand you should see the output of the unit tests.
- Download and install Node.js and npm.
- In a terminal, navigate to the root of the plugin directory and run
npm install - Get some coffee while npm installs the required packages.
- That's it! Now you can run
npm test ./selenium-testsand you should see a Chrome browser window open and the Selenium UI tests run.