Automated Testing in WordPress

  • Create or maintain a WordPress website or sites
  • Create or maintain software related to WordPress [a.k.a. plugins or themes]

What is this talk about?
Which testing stack to use.

Considerations

single site
i.e. a small business
many sites
i.e. A development pipeline for many site [i.e. a WordPress “development agency” that creates custom retail websites]
software
DEVELOPING themes and plugins
websites
USING themes
Gutenberg
React / Gutenberg Editor / Facebook silo]
PHP / vanilla JS / jQuery / mySQL

Basic Tools

xUnit frameworks
Codeception
Codeception is a framework that includes PHPUnit. So always use Codeception.
WP-Browser [code] is a module for Codeception with lots of WordPress specific features.
Jest
Jest is a XUnit runner that uses Node to test Javascript. It’s maintained by Facebook, which owns React. Project Gutenberg is a React app.
WordPress Core tests – PHPUnit and QUnit. Don’t use unless you’re patching actual WordPress core.
WordPress unit test case class – the red meat. Install with Codeception.
WP-CLI – Command line interface for WordPress, great for testing

Drivers

Selenium – allows automated control of browsers
Chromedriver – specific Alphabet driver for Chrome browser
Puppeteer – Selenium driver for Jest

Two Main Types of Testing in WordPress

  1. Unit tests [PHPunit with WordPress. Can be run via PHPUnit or Codeception] for JS use either: Jest for ACTUAL JS unit test, Codeception-JS, or WP-Browser for “WordPress state-full unit tests”.
  2. End-to-end tests [aka “Selenium tests, browser tests, acceptance tests, behavior tests] – Use Codeception with Selenium / WP-Browser / a browser and driver {i.e. Chrome and Chromedriver}. OR Pupeteer with Selenium / a browser and browser drier {i.e. Firefox and Gheckodriver}

Other types of WordPress testing

  • API testing – use Codeception – has API specific module
  • “functional /module / plugin / integration testing” – these are meaningless terms in WordPress. Everyone uses them differently.
  • manual testing – WTF