Search in sources :

Example 1 with Execution

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

the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedTestMethods.

@Test
@DisplayName("is applied on annotated @Test methods")
void appliesTimeoutOnAnnotatedTestMethods() {
    EngineExecutionResults results = executeTests(// 
    request().selectors(// 
    selectMethod(TimeoutAnnotatedTestMethodTestCase.class, "testMethod")).configurationParameter(DEFAULT_TEST_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("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 2 with Execution

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

the class TimeoutExtensionTests method doesNotApplyTimeoutOnAnnotatedTestMethodsUsingDisabledTimeoutMode.

@Test
@DisplayName("is not applied on annotated @Test methods using timeout mode: disabled")
void doesNotApplyTimeoutOnAnnotatedTestMethodsUsingDisabledTimeoutMode() {
    EngineExecutionResults results = executeTests(// 
    request().selectors(// 
    selectMethod(TimeoutAnnotatedTestMethodTestCase.class, "testMethod")).configurationParameter(DEFAULT_TEST_METHOD_TIMEOUT_PROPERTY_NAME, // 
    "42ns").configurationParameter(TIMEOUT_MODE_PROPERTY_NAME, "disabled").build());
    Execution execution = findExecution(results.testEvents(), "testMethod()");
    // 
    assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable()).isEmpty();
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Execution(org.junit.platform.testkit.engine.Execution) 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 3 with Execution

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

the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedTestFactoryMethods.

@Test
@DisplayName("is applied on annotated @TestFactory methods")
void appliesTimeoutOnAnnotatedTestFactoryMethods() {
    EngineExecutionResults results = executeTests(// 
    request().selectors(// 
    selectMethod(TimeoutAnnotatedTestMethodTestCase.class, "testFactoryMethod")).configurationParameter(DEFAULT_TEST_FACTORY_METHOD_TIMEOUT_PROPERTY_NAME, // 
    "42ns").build());
    Execution execution = findExecution(results.containerEvents(), "testFactoryMethod()");
    // 
    assertThat(execution.getDuration()).isGreaterThanOrEqualTo(// 
    Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(1));
    // 
    assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(// 
    TimeoutException.class).hasMessage("testFactoryMethod() 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 4 with Execution

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

the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedTestTemplateMethods.

@Test
@DisplayName("is applied on annotated @TestTemplate methods")
void appliesTimeoutOnAnnotatedTestTemplateMethods() {
    EngineExecutionResults results = executeTests(// 
    request().selectors(// 
    selectMethod(TimeoutAnnotatedTestMethodTestCase.class, "testTemplateMethod")).configurationParameter(DEFAULT_TEST_TEMPLATE_METHOD_TIMEOUT_PROPERTY_NAME, // 
    "42ns").build());
    Stream.of("repetition 1", "repetition 2").forEach(displayName -> {
        Execution execution = findExecution(results.testEvents(), displayName);
        // 
        assertThat(execution.getDuration()).isGreaterThanOrEqualTo(// 
        Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(1));
        // 
        assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(// 
        TimeoutException.class).hasMessage("testTemplateMethod() 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 5 with Execution

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

the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedAfterEachMethods.

@Test
@DisplayName("is applied on annotated @AfterEach methods")
void appliesTimeoutOnAnnotatedAfterEachMethods() {
    EngineExecutionResults results = executeTests(// 
    request().selectors(// 
    selectClass(TimeoutAnnotatedAfterEachMethodTestCase.class)).configurationParameter(DEFAULT_AFTER_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("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

DisplayName (org.junit.jupiter.api.DisplayName)12 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)12 RepeatedTest (org.junit.jupiter.api.RepeatedTest)12 Test (org.junit.jupiter.api.Test)12 EngineExecutionResults (org.junit.platform.testkit.engine.EngineExecutionResults)12 Execution (org.junit.platform.testkit.engine.Execution)12 TimeoutException (java.util.concurrent.TimeoutException)10 PreconditionViolationException (org.junit.platform.commons.PreconditionViolationException)1