Integration Testing With The WordPress Test Suite

Integration Testing With The WordPress Test Suite

James Fawcett

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.

Using Gutenberg

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.

Inside the Gutenberg test suite, you’ll find PHP tests and also JavaScript unit tests. These use the WordPress JavaScript test suit and also other end to end tests. When you use the WordPress plug installer to install Gutenberg, you’ll find that your version has been optimized for use in production environments. You can make the decision to use this or to delete and start from scratch.

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 protected]:WordPress/gutenberg.git

You should then switch to the new directory and you will have Gutenberg. To build the JavaScript files you’ll need to install Webpack using npm. To do this use the follow code:

1            npm install

Then build the JavaScript client using npm:

1            npm run dev

After that you can run the installer script to set up the test suite:

1            bash ./bin/

Once you’ve done this you will see your WordPress site and you’ll be able to run unit tests.

James Fawcett

Author James Fawcett

James is a front and back end Wordpress developer, always interested in the latest technologies and enjoys building the diverse range of sites that Elementary designers throw his way!

More posts by James Fawcett