November 2024
Intermediate to advanced
300 pages
7h 12m
English
As with a lot of other assertion forms, JUnit provides a converse to assertThrows—specifically, the ‘assertDoesNotThrow‘ method. In its simplest form, it takes an executable object (a lambda or method reference). If the invocation of code in the executable doesn’t throw anything, the assertion passes; otherwise, it fails.
Every once in a while, you’ll think you might want to use assertDoesNotThrow…the only problem is, it really doesn’t assert anything about what the executed code does do. Try finding a way to test that elusive “something.”
You might find assertDoesNotThrow useful as the catch-all in a series of tests. Suppose you have a validator that throws an exception in a couple of cases and ...
Read now
Unlock full access