Use this file to discover all available pages before exploring further.
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.
Run these commands from plugins/woocommerce directory:
# Start the test environment (creates if necessary)pnpm env:start# Start and update the environmentpnpm env:dev# Stop the environmentpnpm env:stop# Destroy the environment (removes all files)pnpm env:destroy# Restart the environment (destroy and start)pnpm env:restart
Each plugin in the monorepo has its own isolated environment to prevent conflicts.
# Run all PHP unit testspnpm test:php# Run with HPOS disabledpnpm test:php:hpos-off# Watch mode (auto-run on changes)pnpm test:php:watch
# Run all tests in wp-envpnpm test:php:env# Run with HPOS disabledpnpm test:php:env:hpos-off# Watch mode in environmentpnpm test:php:env:watch
# Run specific test classpnpm test:php:env -- --filter TestClassName# Run specific test methodpnpm test:php:env -- --filter TestClassName::test_method_name# Run specific test suite./vendor/bin/phpunit --testsuite=wc-phpunit-main./vendor/bin/phpunit --testsuite=wc-phpunit-legacy
<?phpnamespace Automattic\WooCommerce\Tests\Internal\Admin;use Automattic\WooCommerce\Internal\Admin\Orders;/** * Tests for Orders class. */class OrdersTest extends \WC_Unit_Test_Case { /** * Test setup. */ public function setUp(): void { parent::setUp(); // Setup code }}
2
Write Test Methods
/** * Test that orders are retrieved correctly. */public function test_get_orders_returns_array() { $orders = new Orders(); $result = $orders->get_orders(); $this->assertIsArray( $result ); $this->assertNotEmpty( $result );}/** * Test order creation. */public function test_create_order_returns_order_id() { $order_id = wc_create_order(); $this->assertIsInt( $order_id ); $this->assertGreaterThan( 0, $order_id );}
3
Use Factory Methods
/** * Test order with products. */public function test_order_with_products() { // Create test data using factories $product = WC_Helper_Product::create_simple_product(); $order = WC_Helper_Order::create_order(); $order->add_product( $product ); $order->save(); $this->assertEquals( 1, $order->get_item_count() );}
# Run all JavaScript tests (from root)pnpm test# Run tests for specific packagepnpm --filter='@woocommerce/components' test# Run tests in watch modepnpm --filter='@woocommerce/components' test -- --watch# Run tests with coveragepnpm --filter='@woocommerce/components' test -- --coverage
# Install Playwright browsers (first time only)pnpm test:e2e:install# Run all E2E testspnpm test:e2e# Run E2E tests with HPOS disabledpnpm test:e2e:hpos-off# Run E2E tests with Gutenberg stablepnpm test:e2e:gb-stable# Run E2E tests with Gutenberg nightlypnpm test:e2e:gb-nightly# Run with specific projectpnpm test:e2e:default --project=e2e
K6 performance tests measure system performance under load.
# Install K6pnpm test:perf:install-k6# Setup performance environmentpnpm env:perf# Run performance testspnpm test:perf# Run with CI setuppnpm test:perf:ci-setup
# Run with verbose outputpnpm test:php:env -- --verbose# Run single test with debuggingpnpm test:php:env -- --filter TestClassName --debug# View wp-env logspnpm wp-env logs