Writing Cleaner, Sturdier Code With Unit Testing

With David Herrera in the Developer track.

Speaker deck

The code you wrote today seems like it plays nicely with the code you wrote yesterday, and you’re pretty sure it will be easy to work with tomorrow. But can you be more confident about it?

Writing unit tests for your code can give you more confidence. Configuring your WordPress development environment for unit testing, though, can also mean confronting many unfamiliar tools at once, including the WordPress core test suite and PHPUnit.

This session will gently introduce unit testing and the tools involved in it. We’ll set up your development environment and scaffold unit tests for your code with WP-CLI, write your first tests with PHPUnit, and learn more about unit testing with the core test suite.

The intended audience is developers with some experience at the command line.

Learning Outcomes

  • Install unit tests inside plugins and themes that extend the core WordPress unit test suite.
  • Write unit tests using PHPUnit assertions.
  • Understand what happens when a test runs.
  • Explore the core unit test suite for testing patterns and guidance.
  • Use WordPress-specific helper testing functions in unit tests.