.ai/skills/woocommerce-dev-cycle/running-tests.md
To run PHP unit tests in the WooCommerce plugin directory, use the following commands:
# Run all PHP unit tests
pnpm run test:php:env
# Run specific test class
pnpm run test:php:env -- --filter TestClassName
# Run specific test method
pnpm run test:php:env -- --filter TestClassName::test_method_name
# Run tests with verbose output
pnpm run test:php:env -- --verbose --filter TestClassName
# Run payment extension suggestions tests
pnpm run test:php:env -- --filter PaymentsExtensionSuggestionsTest
# Run specific test method
pnpm run test:php:env -- --filter PaymentsExtensionSuggestionsTest::test_get_country_extensions_count_with_merchant_selling_online
# Run all tests in a directory
pnpm run test:php:env -- tests/php/src/Internal/Admin/
# Run all Admin tests
pnpm run test:php:env -- --filter "Admin.*Test"
# Run all tests with "Payment" in the name
pnpm run test:php:env -- --filter "Payment"
# Useful during development to quickly identify issues
pnpm run test:php:env -- --stop-on-failure
# Get coverage report (if configured)
pnpm run test:php:env -- --coverage-text
Tests run in Docker via wp-env with auto-configured WordPress/WooCommerce (PHPUnit 9.6.24, PHP 8.1).
The test environment is managed automatically, but you can control it if needed:
# Start the test environment
wp-env start
# Stop the test environment
wp-env stop
# Restart the test environment
wp-env restart
# Destroy and recreate the environment
wp-env destroy
wp-env start
| Problem | Solution |
|---|---|
| "Class not found" errors | Run pnpm install |
| Tests hang/fail to start | wp-env stop && wp-env start or wp-env destroy && wp-env start |
| Permission errors | Check Docker permissions |
| Xdebug warnings | Ignore (don't affect results) |
PHPUnit 9.6.24
.................................................. 50 / 100 ( 50%)
.................................................. 100 / 100 (100%)
Time: 00:02.345, Memory: 24.00 MB
OK (100 tests, 250 assertions)
PHPUnit 9.6.24
.....F................................................. 50 / 100 ( 50%)
.................................................. 100 / 100 (100%)
Time: 00:02.345, Memory: 24.00 MB
There was 1 failure:
1) PaymentsExtensionSuggestionsTest::test_get_country_extensions_count_for_online_merchants with data set "United States" ('US', 5)
Expected 5 extensions for online merchant in US
Failed asserting that 4 matches expected 5.
/path/to/test/file.php:123
FAILURES!
Tests: 100, Assertions: 250, Failures: 1.
Test failures provide:
Run specific tests for the code you're changing:
pnpm run test:php:env -- --filter YourTestClass
Use verbose mode when debugging:
pnpm run test:php:env -- --verbose --filter YourTestClass
Stop on first failure to focus on one issue at a time:
pnpm run test:php:env -- --stop-on-failure --filter YourTestClass
Run all affected tests:
pnpm run test:php:env -- tests/php/src/Internal/YourFeature/
Ensure all tests pass before committing
Check code quality (see code-quality.md)
Test configuration file: plugins/woocommerce/phpunit.xml
This file contains:
To run JavaScript tests for the admin client, navigate to the client/admin directory:
# Navigate to client/admin directory first
cd client/admin
# Run all JavaScript tests
pnpm test:js
# Run tests in watch mode
pnpm test:js -- --watch
# Run a specific test file
pnpm test:js -- status-badge.test.tsx
# Run tests with coverage
pnpm test:js -- --coverage
client/admin/client/**/*.test.tsx or *.test.tsclient/admin/jest.config.jsFor detailed Jest configuration and testing patterns, see client/admin/CLAUDE.md.
Common issues:
client/admin directorypnpm install in the client/admin directorypnpm test:js -- --clearCacheclient/admin/CLAUDE.md