Skip to Content
Effective Unit Testing
book

Effective Unit Testing

by Lasse Koskela
February 2013
Intermediate to advanced content levelIntermediate to advanced
258 pages
7h 26m
English
Manning Publications
Content preview from Effective Unit Testing

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(), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Art of Unit Testing, Second Edition

The Art of Unit Testing, Second Edition

Roy Osherove
Testing with JUnit

Testing with JUnit

Leonard Przybylski, Frank Appel

Publisher Resources

ISBN: 9781935182573Publisher SupportOtherPublisher WebsiteErrata PageSupplemental ContentPurchase Link