Title: Plugin Integration Tests
Author: Pascal Birchler
Published: June 12, 2025
Last modified: July 1, 2025

---

# Plugin Integration Tests

## In this article

 * [Running tests on Travis CI](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#running-tests-on-travis-ci)
 * [Running tests locally](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#running-tests-locally)
    - [1. Install PHPUnit](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#1-install-phpunit)
    - [2. Generate the plugin test files](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#2-generate-the-plugin-test-files)
    - [3. Initialize the testing environment locally](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#3-initialize-the-testing-environment-locally)
    - [4. Run the plugin tests](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#4-run-the-plugin-tests)
 * [Integrating WP Unit Testing in Windows](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#integrating-wp-unit-testing-in-windows)

This guide demonstrates how to run integration tests on both Travis CI and locally.
The scaffolding uses the WordPress CoreCore Core is the set of software required
to run WordPress. The Core Development Team builds WordPress. “unit tests” that 
serve to unit-test WordPress Core. Unit tests are useful for testing plugins and
themes as well, but if they are used in that way, it turns those tests into “integration
tests” – they test the integration between a pluginPlugin A plugin is a piece of
software containing a group of functions that can be added to a WordPress website.
They can extend functionality or add new features to your WordPress websites. WordPress
plugins are written in the PHP programming language and integrate seamlessly with
WordPress. These can be free in the WordPress.org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
or can be cost-based plugin from a third-party./theme and WordPress Core. Proper
unit tests for a plugin or theme would not load WordPress.

## 󠀁[Running tests on Travis CI](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#running-tests-on-travis-ci)󠁿

If you host your plugin on GitHubGitHub GitHub is a website that offers online implementation
of git repositories that can easily be shared, copied and modified by other developers.
Public repositories are free to host, private repositories require a paid subscription.
GitHub introduced the concept of the ‘pull request’ where code changes done in branches
by contributors can be reviewed and discussed before being merged by the repository
owner. [https://github.com/](https://github.com/) and enable [Travis CI](https://docs.travis-ci.com/),
the tests will be run automatically after every commit you make to the plugin.

All you need to do to enable this is copy and then edit the following files from
the [WP-CLI sample plugin](https://github.com/wp-cli/sample-plugin):

 * `.travis.yml`, `phpunit.xml.dist` and `phpcs.ruleset.xml` files
 * `tests` folder

See the docs for an [explanation of what each file does](https://developer.wordpress.org/cli/commands/scaffold/plugin-tests/).
You will then need to specify your unit tests in the `tests/` folder.

## 󠀁[Running tests locally](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#running-tests-locally)󠁿

Running tests locally can be beneficial during development as it is quicker than
committing changes and waiting for Travis CI to run the tests.

We’re going to assume that:

 * You already have a plugin called `my-plugin`
 * You have installed `git`, `svn`, `php`, `apache` ([How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04](https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04))

So, let’s get started:

### 󠀁[1. Install PHPUnit](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#1-install-phpunit)󠁿

The version of PHPUnit to install depends on both PHPPHP PHP (recursive acronym 
for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting
language that is especially suited for web development and can be embedded into 
HTML. [https://www.php.net/manual/en/index.php](https://www.php.net/manual/en/index.php)
and WordPress versions.
 See: [PHPUnit Compatibility and WordPress Versions – Make WordPress Core](https://make.wordpress.org/core/handbook/references/phpunit-compatibility-and-wordpress-versions/)

### 󠀁[2. Generate the plugin test files](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#2-generate-the-plugin-test-files)󠁿

`bash
 wp scaffold plugin-tests my-plugin

This command will generate all the files needed for running tests, including a `.
travis.yml` file.

### 󠀁[3. Initialize the testing environment locally](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#3-initialize-the-testing-environment-locally)󠁿

`cd` into the plugin directory and run the install script (you will need to have`
wget` installed).

`bash
 bash bin/install-wp-tests.sh wordpress_test 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` setup the test database.

 * `wordpress_test` is the name of the test database (**all data will be deleted!**)
 * `root` is the MySQLMySQL MySQL is a relational database management system. A 
   database is a structured collection of data where content, configuration and 
   other options are stored. [https://www.mysql.com](https://www.mysql.com/) user
   name
 * `''` is the MySQL user password
 * `localhost` is the MySQL server host
 * `latest` is the WordPress version; could also be `3.7`, `3.6.2` etc.

NOTE: This script can be run multiple times without errors, but it will _not_ overwrite
previously existing files. So if your DB credentials change, or you want to switch
to a different instance of mysql, simply re-running the script won’t be enough. 
You’ll need to manually edit the `wp-config.php` that’s installed in `/tmp`.

### 󠀁[4. Run the plugin tests](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#4-run-the-plugin-tests)󠁿

    ```bash
    phpunit
    ```

If you have trouble running the install script or PHPUnit, check [Support section](http://wp-cli.org/#support)
for help and answers to common issues.

## 󠀁[Integrating WP Unit Testing in Windows](https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests/?output_format=md#integrating-wp-unit-testing-in-windows)󠁿

Tried and gotten stuck setting up unit tests for your project in Windows?

First, know that some WP-CLIWP-CLI WP-CLI is the Command Line Interface for WordPress,
used to do administrative and development tasks in a programmatic way. The project
page is [http://wp-cli.org/](http://wp-cli.org/) [https://make.wordpress.org/cli/](https://make.wordpress.org/cli/)
commands don’t work in Windows, so you’ll want to use Cygwin. Cygwin is also [preferred by the WordPress core project](https://make.wordpress.org/core/handbook/tutorials/working-with-patches/).

Second, the `bin/install-wp-tests.sh` script doesn’t work directly in Windows. Windows
10 [introduced a Windows Subsystem for Linux](http://www.pcworld.com/article/3106463/windows/how-to-get-bash-on-windows-10-with-the-anniversary-update.html)
but older versions require extra effort. Cygwin is preferred because it runs bash
scripts by default.

Third, the bash installation script uses `which`, a Linux command not available 
by default in Windows. `cURL`, `svn` and `wget` all can be installed in Windows 
as separate packages.

Lastly, sometimes the bash script fails to build WordPress because of how it uses
tmp folders. If it fails, then you can manually install WordPress to a writeable
directory, and then manually create `wp-tests-config.php`.

First published

June 12, 2025

Last updated

July 1, 2025

Edit article

[ Improve it on GitHub: Plugin Integration Tests ](https://github.com/wp-cli/handbook/edit/main/plugin-unit-tests.md)

Changelog

[ See list of changes: Plugin Integration Tests ](https://github.com/wp-cli/handbook/commits/main/plugin-unit-tests.md)

[  Previous: Identify a Plugin or Theme Conflict](https://make.wordpress.org/cli/handbook/how-to/identify-plugin-theme-conflict/)

[  Next: References](https://make.wordpress.org/cli/handbook/references/)