Search in sources :

Example 16 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults 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 17 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults 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)

Example 18 with EngineExecutionResults

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

the class TimeoutExtensionTests method reportsIllegalTimeoutDurations.

@Test
@DisplayName("reports illegal timeout durations")
void reportsIllegalTimeoutDurations() {
    EngineExecutionResults results = executeTestsForClass(IllegalTimeoutDurationTestCase.class);
    Execution execution = findExecution(results.testEvents(), "testMethod()");
    // 
    assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(// 
    PreconditionViolationException.class).hasMessage("timeout duration must be a positive number: 0");
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Execution(org.junit.platform.testkit.engine.Execution) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) 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 19 with EngineExecutionResults

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

the class TimeoutExtensionTests method failsMethodsWithoutInterruptedException.

@Test
@DisplayName("fails methods that do not throw InterruptedException")
void failsMethodsWithoutInterruptedException() {
    EngineExecutionResults results = executeTestsForClass(MethodWithoutInterruptedExceptionTestCase.class);
    Execution execution = findExecution(results.testEvents(), "methodThatDoesNotThrowInterruptedException()");
    // 
    assertThat(execution.getDuration()).isGreaterThanOrEqualTo(// 
    Duration.ofMillis(1)).isLessThan(Duration.ofSeconds(1));
    assertThat(execution.getTerminationInfo().getExecutionResult().getStatus()).isEqualTo(FAILED);
    // 
    assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(// 
    TimeoutException.class).hasMessage("methodThatDoesNotThrowInterruptedException() timed out after 1 millisecond");
}
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 20 with EngineExecutionResults

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

the class IgnoreConditionTests method ignoredAndNotIgnoredTestMethods.

@Test
void ignoredAndNotIgnoredTestMethods() {
    EngineExecutionResults executionResults = executeTestsForClass(IgnoredMethodsTestCase.class);
    Events containers = executionResults.containerEvents();
    Events tests = executionResults.testEvents();
    // executionResults.allEvents().debug();
    // executionResults.allEvents().debug(System.err);
    // containers.debug();
    // tests.debug(System.err);
    // tests.debug();
    // tests.skipped().debug();
    // tests.started().debug();
    // tests.succeeded().debug();
    // executionResults.allEvents().executions().debug();
    // containers.executions().debug();
    // tests.executions().debug();
    executionResults.allEvents().executions().assertThatExecutions().hasSize(5);
    containers.executions().assertThatExecutions().hasSize(2);
    tests.executions().assertThatExecutions().hasSize(3);
    // @formatter:off
    // tests.debug().assertEventsMatchExactly(
    tests.assertEventsMatchExactly(event(test("ignoredWithCustomMessage"), skippedWithReason("Ignored Method")), event(test("notIgnored"), started()), event(test("notIgnored"), finishedSuccessfully()), event(test("ignoredWithDefaultMessage"), skippedWithReason(reason -> reason.endsWith("ignoredWithDefaultMessage() is disabled via @org.junit.Ignore"))));
// @formatter:on
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Events(org.junit.platform.testkit.engine.Events) Test(org.junit.jupiter.api.Test)

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