O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required