How Ya Feelin’ Now?

This book provides two starter examples for a few reasons. The first example (Chapter 1, Building Your First JUnit Test) demonstrates the basics of how to use JUnit and minimizes the distraction of involved logic. That’s not good enough for Pat, who would claim, “See? Unit testing is only good on toy examples.”

Hence the second example in this chapter, which contains a reasonably complex set of logic. We hope it doesn’t dissuade you from wanting to unit-test your code, but this is reality: methods like matches() embody a surprising number of branches and cases that each suggest the need for yet another test.

So far, we’ve covered only two paths through the matches() method. The smaller effort required to write the second ...

Get Pragmatic Unit Testing in Java 8 with JUnit now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.