Search in sources :

Example 91 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TimeoutExtensionTests method applyTimeoutOnAnnotatedTestMethodsUsingDisabledOnDebugTimeoutMode.

@Test
@DisplayName("is not applied on annotated @Test methods using timeout mode: disabled")
void applyTimeoutOnAnnotatedTestMethodsUsingDisabledOnDebugTimeoutMode() {
    EngineExecutionResults results = executeTests(// 
    request().selectors(// 
    selectMethod(TimeoutAnnotatedTestMethodTestCase.class, "testMethod")).configurationParameter(DEFAULT_TEST_METHOD_TIMEOUT_PROPERTY_NAME, // 
    "42ns").configurationParameter(TIMEOUT_MODE_PROPERTY_NAME, "disabled_on_debug").build());
    Execution execution = findExecution(results.testEvents(), "testMethod()");
    // 
    assertThat(execution.getDuration()).isGreaterThanOrEqualTo(// 
    Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(2));
    // Should we test if we're debugging? This test will fail if we are debugging.
    if (RuntimeUtils.isDebugMode()) {
        // 
        assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable()).isEmpty();
    } else {
        // 
        assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(// 
        TimeoutException.class).hasMessage("testMethod() timed out after 10 milliseconds");
    }
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Execution(org.junit.platform.testkit.engine.Execution) TimeoutException(java.util.concurrent.TimeoutException) RepeatedTest(org.junit.jupiter.api.RepeatedTest) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 92 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TimeoutExtensionTests method includesClassNameIfMethodIsNotInTestClass.

@Test
@DisplayName("includes fully qualified class name if method is not in the test class")
void includesClassNameIfMethodIsNotInTestClass() {
    EngineExecutionResults results = executeTestsForClass(NestedClassWithOuterSetupMethodTestCase.class);
    Execution execution = findExecution(results.testEvents(), "testMethod()");
    // 
    assertThat(execution.getDuration()).isGreaterThanOrEqualTo(// 
    Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(1));
    // 
    assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(// 
    TimeoutException.class).hasMessageEndingWith("$NestedClassWithOuterSetupMethodTestCase#setUp() timed out after 10 milliseconds");
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Execution(org.junit.platform.testkit.engine.Execution) TimeoutException(java.util.concurrent.TimeoutException) RepeatedTest(org.junit.jupiter.api.RepeatedTest) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 93 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedBeforeEachMethods.

@Test
@DisplayName("is applied on annotated @BeforeEach methods")
void appliesTimeoutOnAnnotatedBeforeEachMethods() {
    EngineExecutionResults results = executeTests(// 
    request().selectors(// 
    selectClass(TimeoutAnnotatedBeforeEachMethodTestCase.class)).configurationParameter(DEFAULT_BEFORE_EACH_METHOD_TIMEOUT_PROPERTY_NAME, // 
    "42ns").build());
    Execution execution = findExecution(results.testEvents(), "testMethod()");
    // 
    assertThat(execution.getDuration()).isGreaterThanOrEqualTo(// 
    Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(1));
    // 
    assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(// 
    TimeoutException.class).hasMessage("setUp() timed out after 10 milliseconds");
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Execution(org.junit.platform.testkit.engine.Execution) TimeoutException(java.util.concurrent.TimeoutException) RepeatedTest(org.junit.jupiter.api.RepeatedTest) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 94 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedBeforeAllMethods.

@Test
@DisplayName("is applied on annotated @BeforeAll methods")
void appliesTimeoutOnAnnotatedBeforeAllMethods() {
    EngineExecutionResults results = executeTests(// 
    request().selectors(// 
    selectClass(TimeoutAnnotatedBeforeAllMethodTestCase.class)).configurationParameter(DEFAULT_BEFORE_ALL_METHOD_TIMEOUT_PROPERTY_NAME, // 
    "42ns").build());
    Execution execution = findExecution(results.containerEvents(), TimeoutAnnotatedBeforeAllMethodTestCase.class.getSimpleName());
    // 
    assertThat(execution.getDuration()).isGreaterThanOrEqualTo(// 
    Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(1));
    // 
    assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(// 
    TimeoutException.class).hasMessage("setUp() timed out after 10 milliseconds");
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Execution(org.junit.platform.testkit.engine.Execution) TimeoutException(java.util.concurrent.TimeoutException) RepeatedTest(org.junit.jupiter.api.RepeatedTest) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 95 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedAfterAllMethods.

@Test
@DisplayName("is applied on annotated @AfterAll methods")
void appliesTimeoutOnAnnotatedAfterAllMethods() {
    EngineExecutionResults results = executeTests(// 
    request().selectors(// 
    selectClass(TimeoutAnnotatedAfterAllMethodTestCase.class)).configurationParameter(DEFAULT_AFTER_ALL_METHOD_TIMEOUT_PROPERTY_NAME, // 
    "42ns").build());
    Execution execution = findExecution(results.containerEvents(), TimeoutAnnotatedAfterAllMethodTestCase.class.getSimpleName());
    // 
    assertThat(execution.getDuration()).isGreaterThanOrEqualTo(// 
    Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(1));
    // 
    assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(// 
    TimeoutException.class).hasMessage("tearDown() timed out after 10 milliseconds");
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Execution(org.junit.platform.testkit.engine.Execution) TimeoutException(java.util.concurrent.TimeoutException) RepeatedTest(org.junit.jupiter.api.RepeatedTest) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

EngineExecutionResults (org.junit.platform.testkit.engine.EngineExecutionResults)139 Test (org.junit.jupiter.api.Test)134 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)32 DynamicTest (org.junit.jupiter.api.DynamicTest)30 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)30 Events (org.junit.platform.testkit.engine.Events)27 DisplayName (org.junit.jupiter.api.DisplayName)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)15 IOException (java.io.IOException)12 Execution (org.junit.platform.testkit.engine.Execution)12 TimeoutException (java.util.concurrent.TimeoutException)10 List (java.util.List)8 ExtensionConfigurationException (org.junit.jupiter.api.extension.ExtensionConfigurationException)8 ArrayList (java.util.ArrayList)7 AfterAll (org.junit.jupiter.api.AfterAll)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 BeforeAll (org.junit.jupiter.api.BeforeAll)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Nested (org.junit.jupiter.api.Nested)7 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)7