Last active
July 3, 2019 15:01
-
-
Save wkorando/b939c9b66af3595fb503fa5458122784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Timeout(3) // Sets timeout limit for each test in class to three seconds | |
@TestMethodOrder(OrderAnnotation.class) | |
public class TimeoutTest { | |
static int testCounter = 0; | |
@BeforeAll | |
@Timeout(2) // If this timeout is exceeded, all tests are failed | |
public static void classSetupWithTimeout() throws InterruptedException { | |
// ...complex setup code | |
} | |
@BeforeEach | |
@Timeout(2) // If timeout is exceeded current test is failed, but next test will be | |
// attempted | |
public void methodSetupWithTimeout() throws InterruptedException { | |
Thread.sleep(1500 * testCounter); | |
} | |
@Test | |
@Timeout(unit = TimeUnit.MILLISECONDS, value = 500L) // Default unit is seconds, but other options available | |
@Order(1) | |
public void testTestCaseTimeout() throws InterruptedException { | |
Thread.sleep(600); | |
} | |
@Test | |
@Order(2) | |
public void testExceedsClassTimeLimit() throws InterruptedException { | |
Thread.sleep(3500); | |
} | |
@Test | |
@Order(3) | |
public void timeoutTest1() { | |
testCounter = testCounter + 1; | |
} | |
@Test | |
@Order(4) // Will fail due to timeout | |
public void timeoutTest2() { | |
testCounter = testCounter + 1; | |
} | |
@Test | |
@Order(5) // Will fail due to timeout, but still attempted | |
public void timeoutTest3() { | |
testCounter = testCounter + 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment