Integration tests are there to cover any effects that code has on the environment that it is in. For this type of testing, phpunit is normally used in different ways. Here, we are going to take you through how you can use integration testing within the WordPress test suite, keep reading if you’d like to find out more.
The WordPress Test Suite
There is a community project that is called varying vagrant vagrants which is also known as VVV. This project is used to provide a system that lets you use Vagrant to create local WordPress. Within VVV users can develop the WordPress core using the site that is designed for it. You can also manage the source of the WordPress test suit using the SVN repository that it installs from WordPress.
Using VVV to Set It Up
The tests for the plugin are created using the WP CLI command and you will see this when you have installed VVV. You can then use this plugin to open a new shell and then switch to the bin dir. After that you should run the test install script which would be:
1 bash ./install-wp-tests wordpress_unit_tests wordpress wordpress localhost
After this you should switch to the original plugin directory. From there, you’ll be able to run the tests without any problems creeping up.
The Gutenberg project is a great way of letting people update how they make WordPress and what they use to do it. The installation of Gutenberg Docker is fairly straightforward and useful in allowing for integration testing with the WordPress Test Suite. When you use Gutenberg, you are using npm-scripts which are great for making it easy to run commands with similar arguments when you run common tasks like unit tests or code linting.
If you’d like to do this, you can use a shell in the plugin directory in your local WordPress site. After that clone Gutenberg using the command:
1 git clone email@example.com:WordPress/gutenberg.git
1 npm install
1 npm run dev
After that you can run the installer script to set up the test suite:
1 bash ./bin/install-docker.sh
Once you’ve done this you will see your WordPress site and you’ll be able to run unit tests.