Unit Testing and WordPress Plugins
What is Unit Testing?
Unit testing is the method by which programmers ensure each individual component of our application is functioning correctly and as expected.
In other words, make sure your code works
So what's the big deal?
A unit is the smallest testable block of code in your program.
Scripted and Automated
Unit tests follow a pre-defined routine and are usually automated.
Benefits of Unit Testing
- Efficient debugging
- Encourages good coding practices
- Makes your code more portable
- Helps prevent regressions
Unit testing is a tool, not a solution.
What Should You Unit Test?
- Any code that could break
- Libraries, frameworks, modules, etc.
- Code with multiple authors
- Portable code
What Should You Not Test
- UI and UX design
- 3rd party code integration
Unit Testing Workflows
- Tests first
- Bug reports
- Continuous integration
- Just do it
Tools for WordPress Testing
- WordPress Unit Testing Framework
- WordPress Plugin Tests by Ben Balter