Search in sources :

Example 11 with EngineExecutionResults

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

the class TestWatcherTests method testWatcherIsInvokedForRepeatedTestMethods.

@Test
void testWatcherIsInvokedForRepeatedTestMethods() {
    EngineExecutionResults results = executeTestsForClass(TrackingTestWatcherRepeatedTestMethodsTestCase.class);
    results.containerEvents().assertStatistics(stats -> stats.skipped(1).started(5).succeeded(5).aborted(0).failed(0));
    results.testEvents().assertStatistics(stats -> stats.dynamicallyRegistered(6).skipped(0).started(6).succeeded(2).aborted(2).failed(2));
    ArrayList<String> expectedMethods = new ArrayList<>(testWatcherMethodNames);
    // Since the @RepeatedTest container is disabled, the individual invocations never occur.
    assertThat(TrackingTestWatcher.results.keySet()).containsAll(expectedMethods);
    // 2 => number of iterations declared in @RepeatedTest(2).
    TrackingTestWatcher.results.forEach((methodName, uidList) -> assertEquals("testDisabled".endsWith(methodName) ? 1 : 2, uidList.size()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) ArrayList(java.util.ArrayList) 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)

Example 12 with EngineExecutionResults

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

the class TestWatcherTests method testWatcherInvokedForTestMethodsInTestCaseWithProblematicConstructor.

@Test
void testWatcherInvokedForTestMethodsInTestCaseWithProblematicConstructor() {
    EngineExecutionResults results = executeTestsForClass(ProblematicConstructorTestCase.class);
    results.testEvents().assertStatistics(stats -> stats.skipped(0).started(8).succeeded(0).aborted(0).failed(8));
    assertThat(TrackingTestWatcher.results.keySet()).containsExactly("testFailed");
    assertThat(TrackingTestWatcher.results.get("testFailed")).hasSize(8);
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) 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)

Example 13 with EngineExecutionResults

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

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

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

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