Testing extensions and maintaining quality code

These pages contain a canonical guide for testing the things you build with WooCommerce. The objective of these pages is to provide a foundational knowledge of the tools, processes, and best practices for anyone developing a WooCommerce extension.


Table of Contents

The Value of Testing

  • Automated testing is an accepted best practice in software development, but its usefulness is often taken as self-evident — making it harder for individual developers to really understand and feel the value. This section shows when testing provides benefits and what those benefits are, backed by research.

Types of testing

  • Smoke testing
  • End-to-end Testing
  • Unit testing
  • API testing
  • Performance testing
  • Manual testing
  • Visual regression testing

Testing tools

🚧 Environment management

  • Docker
  • Homebrew
  • VVV
  • wp-env
  • wp-cli
  • @woocommerce/e2e-environment

🚧 Test runners, frameworks, and libraries

  • PHPUnit
  • Jest
  • Puppeteer
  • @woocommerce/e2e-core-tests
  • @woocommerce/e2e-utils
  • @woocommerce/api

🚧 Linting and consistency tools

  • PHP Codesniffer
  • ESLint

🚧 Debugging tools

  • Xdebug
  • Query Monitor
  • Debug Bar
  • Enabling WP DEBUG logging
  • Mail Poet Email Logging plugin
  • WordPress and WooCommerce Beta Tester Plugins
  • REST API clients
  • React Developer Tools

Setting up a local environment for testing

  • Installing dependencies
  • Establishing a testing architecture
  • Typical testing workflows

Best practices for writing and running tests

Critical Flows

  • What are critical flows?
  • Identifying an extension’s critical flows
  • Testing critical flows
  • Maintaining critical flows over time

🚧 Unit Testing

  • Setting up PHPUnit

End to End Testing

  • Using the WooCommerce E2E-boilerplate project
  • Setting up WooCommerce E2E tools

🚧 Setting up Linting

  • Setting up PHP Codesniffer and WooCommerce Sniffs
  • Setting up ESLint for JavaScript