B.3. Built-in rules
JUnit doesn’t just provide the rules API as an extension point for its users: a number of essential JUnit features have been implemented using the same API, including a global timeout for a whole test class, a more sophisticated way of dealing with expected exceptions, and management of temporary filesystem resources. Let’s start the tour by looking at how you can configure a global timeout for all tests in a class.
B.3.1. Setting a global timeout
The rules API gives you the option of defining a timeout just once for all tests in the class. This listing shows an example of such a global timeout:
Listing B.1. Specifying a global timeout for all test methods in the class
There are three things to note about listing B.1:
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.