1. Home
  2. Docs
  3. Application Framework
  4. Plugin Guide
  5. Testing


You can write unit and integration tests for your plugin by following the example test case in the boilerplate located at plugin-dir/tests/test-plugin.php. Tests can all be added to the provided test class, or new test classes with individual test cases can be created and placed in the /tests subfolder of your plugin.

To run the tests, you will use the WP CLI and the testing framework. More information can be found at https://make.wordpress.org/cli/handbook/plugin-unit-tests/.

To set up the testing scaffolding, use:

$ wp scaffold plugin-tests myplugin-slug
$ cd $(wp plugin path myplugin-slug --dir)
$ bin/install-wp-tests.sh wordpress_test root '' localhost latest

  • wordpress_test is the name of your test database (all data will be deleted!)
  • root is the MySQL user name
  • ” is the MySQL user password
  • localhost is the MySQL server host
  • latest is the wordpress version

You must also have the standalone mwp framework present in the development environment for the plugin you are testing. It must be in the /plugins/mwp-framework directory.

After your testing environment has been set up, you simply need to run phpunit from the working directory of your plugin.

$ cd $(wp plugin path myplugin-slug --dir)
$ phpunit

Was this article helpful to you? Yes No

How can we help?