Integration testing

Integration tests are used to check how components work inside WordPress.

The best way set up an integration test is to use either Codeception or WP-CLI.

WP-CLI

If you don't have WP-CLI installed on your system, install it. You can find the documentation on starting unit tests here.

Assuming you have a plugin on your testing environment, run the following in the project root folder:

wp scaffold plugin-tests my-plugin

This will create several new files and folders in your plugin:

bin/
    install-wp-tests.sh
tests/
    bootstrap.php
    test-sample.php
phpunit.xml
.travis.yml

To initialize the testing environment locally, go to your plugin directory and run the install script.

bin/install-wp-tests.sh wordpress_unit_tests root '' localhost latest

The install script first installs a copy of WordPress in the /tmp directory (by default) as well as the WordPress unit testing tools. Then it creates a database to be used while running tests. The parameters that are passed to install-wp-tests.sh set up the test database. Be sure that your MySQL service is up and running if you're running tests outside VVV.

After that, you can run the plugin tests by writing

vendor/bin/phpunit

Useful links

Codeception for WordPress Four WordPress Integration Testing Easy Pieces Integration Tests with WordPress & PHPUnit