Expected Exceptions using JUnit
Explore how to handle expected exceptions in JUnit by using the ExpectedException rule and similar techniques. Understand how to set expectations for exceptions, verify their messages, and simplify test code while managing checked exceptions effectively in Java unit tests.
We'll cover the following...
We'll cover the following...
JUnit allows us to define custom rules which can provide greater control over what happens during the flow of test execution.
In a sense, custom rules provide a capability similar to aspect-oriented programming in that they provide a way to automatically attach a cross-cutting concern to a set of tests.
JUnit provides a few useful rules out of the box, meaning we don’t have to code them ourselves. ...