November 2024
Intermediate to advanced
300 pages
7h 12m
English
In addition to ensuring that the happy path through your code works, you also need to verify the unhappy cases. For example, you’ll want to write tests that demonstrate when code can throw exceptions. These tests are necessary to provide a full understanding of the behaviors to developers who must work with the code.
The ever-evolving Java language has driven the continual development of JUnit as well—there are no fewer than four ways to write exception-based tests in JUnit. You’ll take a look at a couple of these.
Let’s examine a simple case: ensure the Account code throws an InsufficientFundsException when a client attempts to withdraw more than the available balance.
The assertThrows assertion, ...
Read now
Unlock full access