Automated tests are crucial for ensuring that changes to WordPress coreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. do not introduce regressions. This guide covers how to run the 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/preface.php and End-to-End (E2E) test suites locally.
Prerequisites
Ensure a local testing environment is set up. See Set Up a Testing Environment.
To learn how to apply patches before running tests, see Test Core Tickets with Grunt.
Run PHP Tests (PHPUnit)
The PHP unit tests cover the backend PHP code of WordPress.
To run the full PHPUnit test suite:
npm run test:php
Running Specific Tests
To run a specific group of tests (often related to a specific TracTrac Trac is the place where contributors create issues for bugs or feature requests much like GitHub.https://core.trac.wordpress.org/. ticket, if tagged):
npm run test:php -- --group 27307
To run tests within a specific class or file (filterFilter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output.):
npm run test:php -- --filter WP_Test_User_Query
Run End-to-End (E2E) Tests
E2E tests verify the behavior of the application from the user’s perspective, running in a browser environment.
To run the end-to-end test suite:
npm run test:e2e
Troubleshooting
“Error: ECONNREFUSED”
- Cause: The local environment or Docker is not running.
- Fix: Start Docker Desktop and run:
npm run env:start
“Database connection failed”
- Cause: The database container isn’t ready or needs to be reset.
- Fix: Wait a few seconds and try again, or reset the environment:
npm run env:reset
npm run env:install