Merging code, especially when authored by multiple people, can lend itself to a lot of risk.
As a code base grows, there may be an underlying feeling that more bugs exist than we can find by digging through our code editor or our application’s various screens.
Unit testing is a process that lets us test the individual components of our software application in an automated fashion. When we author unit tests we may be codifying decisions we have made, verifying the integrity of our expected inputs/outputs, or simply checking that our objects have certain properties after being constructed. In any case, writing tests can save us a lot of time because it takes away the need to manually verify that our code is working as expected.
This post is a work-in-progress, but our goal is to demonstrate the steps for installing and using the PHPUnit software on both Windows and Mac systems, with the goal of implementing unit testing in PHP applications.
We will start off by discussing unit testing in an abstract sense, but we will also take a look at how we can setup unit tests within the WordPress environment using WP-CLI.
Software
Windows Software
Mac Software
Resources
Getting started with PHPUnit
Pippin Williamson’s series on Unit Tests For WordPress Plugins
Make WordPress Blog post on Plugin Unit Tests
WP-CLI documentation for the scaffolding plugin tests
PHPUnit assertions
Presentations on PHPUnit
Leave a Reply