JUnit 5 Timeouts Examples
In JUnit 5, we can use @Timeout to fail a test if the execution time exceeds a given duration. P.S Tested with JUnit 5.5.2 1. @Timeout TimeOutExample1.java package com.mkyong.timeout; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import java.util.concurrent.TimeUnit; public class TimeOutExample1 { // timed out after 5 seconds @BeforeEach @Timeout(5) void setUpDB() throws InterruptedException { //TimeUnit.SECONDS.sleep(10); …