6.3. Never-failing tests

Never-failing tests are like Chuck Norris—they never fail—and that’s a bad thing. A test that can’t fail has no value, as it will never alert you to a mishap. A test that can never fail is probably worse than not having that test, as it creates a false sense of security.

6.3.1. Example

Perhaps the single most common context where never-failing tests are found is in tests that check for an expected exception to be thrown.[5] Here is an example of such a test.

5 Another common type of a never-failing test is a test without assertions.

Listing 6.3. Test that never fails
@Test public void includeForMissingResourceFails() { try { new Environment().include("somethingthatdoesnotexist"); } catch (IOException e) { assertThat(e.getMessage(), ...

Get Effective Unit Testing 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.