Skip to main content
Testing is a critical part of the WooCommerce development process. All code contributions should include appropriate tests, and existing tests must pass before changes can be merged.

Testing Overview

WooCommerce uses multiple testing frameworks to ensure code quality:

PHPUnit

Unit and integration tests for PHP code

Jest

Unit tests for JavaScript and React components

Playwright

End-to-end and API testing

Test Environment Setup

WooCommerce uses @wordpress/env (wp-env) to create isolated Docker-based testing environments.

Prerequisites

  • Docker installed and running
  • PNPM installed
  • Sufficient disk space for Docker containers

Environment Commands

Run these commands from plugins/woocommerce directory:
Each plugin in the monorepo has its own isolated environment to prevent conflicts.

Environment Details

PHPUnit Tests

PHPUnit tests validate PHP code functionality, including classes, functions, and WordPress integration.

Running PHPUnit Tests

PHPUnit Test Structure

Tests are organized to mirror the source code structure:

Writing PHPUnit Tests

1

Create Test Class

tests/php/src/Internal/Admin/OrdersTest.php
2

Write Test Methods

3

Use Factory Methods

PHPUnit Configuration

The phpunit.xml file configures PHPUnit:
phpunit.xml

JavaScript/Jest Tests

Jest tests validate JavaScript and React component functionality.

Running Jest Tests

Writing Jest Tests

OrderStatus.test.js

End-to-End (E2E) Tests

Playwright tests simulate real user interactions in a browser environment.

Running E2E Tests

Running API Tests

Writing E2E Tests

1

Create Test File

tests/e2e-pw/tests/merchant/create-order.spec.ts
2

Write Test Cases

E2E Test Helpers

Performance Tests

K6 performance tests measure system performance under load.

Test Coverage Requirements

When contributing code, ensure appropriate test coverage:

What to Test

  • Unit tests for all new classes and methods
  • Integration tests for WordPress interactions
  • E2E tests for user-facing functionality
  • API tests for new endpoints

Coverage Guidelines

Aim for:
  • 80%+ code coverage for new PHP classes
  • 100% coverage for critical payment/order processing code
  • E2E tests for all user-facing features
  • API tests for all REST API endpoints

CI/CD Testing

All pull requests automatically run tests in CI:

Automated Test Runs

  • PHP Unit Tests: PHP 7.4, 8.5 with WordPress latest/latest-1
  • E2E Tests: Multiple shards for parallel execution
  • API Tests: Full API test suite
  • Linting: PHP, JavaScript, and markdown linting
  • PHPStan: Static analysis for type safety

Test Environments

CI tests run in multiple configurations:
All tests must pass before a PR can be merged. Fix any failing tests before requesting review.

Debugging Tests

PHPUnit Debugging

Playwright Debugging

Common Testing Issues

Ensure Docker Desktop is running before starting wp-env:
If port 8888 is in use, wp-env will fail to start:
Sometimes tests fail due to database state:
If Playwright browser installation fails:

Next Steps

Git Workflow

Learn the Git workflow for committing and creating PRs

Coding Standards

Review coding standards and linting requirements