11 Unit testing practices
This chapter covers
- Effectively and reliably unit testing all the behaviors of a piece of code
- Ensuring that tests are understandable and that failures are well explained
- Using dependency injection to ensure that code is testable
Chapter 10 identified a number of principles that can be used to guide us toward writing effective unit tests. This chapter builds on these principles to cover a number of practical techniques that we can apply in our everyday coding.
Chapter 10 described the key features that good unit tests should exhibit. The motivation for many of the techniques described in this chapter directly follow from these, so as a reminder, the key features are as follows:
-
Accurately detects breakages —If ...
Get Good Code, Bad Code now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.