Is the Test Really Testing Anything?

You might even want to consider building a strong discipline around ensuring that the tests fail. Consider always ensuring that the test fails. It’s possible to write a test that doesn’t really verify what you think it does, which can lead to bad, costly assumptions on your part.

In fact, programmers following the practice of test-driven development (TDD) always demonstrate test failure first, to demonstrate that the code they write is responsible for making the test pass. See Chapter 12, Test-Driven Development for more on how TDD practitioners build a cycle around this discipline.


Deliberately fail ...

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.