Unit tests are a tool that developers use to test that code is performing properly. The idea behind unit tests is to create a set of tests that determine if the code you have written is doing what it is supposed to do.

A unit test should check that one piece of code, such as a function or method, runs properly and returns the expected results.

Through this tutorial series, we will walk through how to setup unit tests for your plugin, how to write the unit tests, how to run the tests, how to write testable code, and also some of the tools that we have available to us to help us leverage the benefits of unit tests. I also want to try and answer the question of “why” you should be writing unit tests for your plugin.

As we go through this tutorial series, I will be writing real unit tests for real plugins to try and better illustrate exactly how they work and how you can implement them in your own plugins.

For this series, we will be using PHPUnit, WP-CLI, and Travis-CI and the primary tools in our unit testing setup.