assertTimeoutPreemptively method

This lesson demonstrates how to use assertTimeoutPreemptively method in JUnit 5 to assert timeout conditions.

We'll cover the following

assertTimeoutPreemptively() method

Assertions API provide static assertTimeoutPreemptively() method. It is used to test long-running tasks. If given task inside the test case takes more than the specified duration, then the test will fail.

The executable provided to the test case will be executed in the different thread as that of the calling code. Also, the execution of the executable will be preemptively aborted if the timeout is exceeded.

Get hands-on with 1400+ tech skills courses.