Asserting timeouts
To assess timeouts in JUnit 5 tests, Jupiter provides two assertions: assertTimeout and assertTimeoutPreemptively. On the one hand, assertTimeout, allows us to verify the timeout of a given operation. In this assertion, the expected time is defined using the class Duration of the standard Java package java.time.
We are going to see several running examples to clarify the use of this assertion method. In the following class, we find two tests using assertTimeout. The first test is designed to be succeeded, due to the fact that we are expecting that a given operation takes less than 2 minutes, and we are doing nothing there. On the other side, the second test will fail, since we are expecting that a given operation takes ...
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.
Read now
Unlock full access