Search in sources :

Example 26 with EngineExecutionResults

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

the class ExceptionHandlingTests method checkedExceptionInAfterEachIsSuppressedByExceptionInTest.

@Test
void checkedExceptionInAfterEachIsSuppressedByExceptionInTest() {
    Class<?> testClass = FailureTestCase.class;
    FailureTestCase.exceptionToThrowInAfterEach = Optional.of(new IOException("checked"));
    EngineExecutionResults executionResults = executeTests(selectMethod(testClass, "testWithUncheckedException"));
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(testClass), started()), // 
    event(test("testWithUncheckedException"), started()), event(// 
    test("testWithUncheckedException"), finishedWithFailure(// 
    instanceOf(RuntimeException.class), // 
    message("unchecked"), // 
    suppressed(0, instanceOf(IOException.class), message("checked")))), // 
    event(container(testClass), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 27 with EngineExecutionResults

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

the class ExceptionHandlingTests method uncheckedExceptionInTestMethodIsRegistered.

@Test
void uncheckedExceptionInTestMethodIsRegistered() {
    EngineExecutionResults executionResults = executeTests(selectMethod(FailureTestCase.class, "testWithUncheckedException"));
    Events tests = executionResults.testEvents();
    tests.assertStatistics(stats -> stats.started(1).failed(1));
    // 
    tests.failed().assertEventsMatchExactly(event(test("testWithUncheckedException"), finishedWithFailure(instanceOf(RuntimeException.class), message("unchecked"))));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Events(org.junit.platform.testkit.engine.Events) Test(org.junit.jupiter.api.Test)

Example 28 with EngineExecutionResults

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

the class DynamicNodeGenerationTests method singleDynamicTestIsExecutedWhenDiscoveredByIterationIndex.

@Test
void singleDynamicTestIsExecutedWhenDiscoveredByIterationIndex() {
    var methodSelector = selectMethod(MyDynamicTestCase.class, "dynamicStream");
    EngineExecutionResults executionResults = executeTests(selectIteration(methodSelector, 1));
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(MyDynamicTestCase.class), started()), // 
    event(container("dynamicStream"), started()), // 
    event(dynamicTestRegistered("dynamic-test:#2")), // 
    event(test("dynamic-test:#2", "failingTest"), started()), // 
    event(test("dynamic-test:#2", "failingTest"), finishedWithFailure(message("failing"))), // 
    event(container("dynamicStream"), finishedSuccessfully()), // 
    event(container(MyDynamicTestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 29 with EngineExecutionResults

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

the class DynamicNodeGenerationTests method dynamicContainersAreExecutedFromIterable.

@Test
void dynamicContainersAreExecutedFromIterable() {
    EngineExecutionResults executionResults = executeTests(selectMethod(MyDynamicTestCase.class, "dynamicContainerWithIterable"));
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(MyDynamicTestCase.class), started()), // 
    event(container("dynamicContainerWithIterable"), started()), // 
    event(dynamicTestRegistered("dynamic-container:#1")), // 
    event(container("dynamic-container:#1"), started()), // 
    event(dynamicTestRegistered("dynamic-test:#1")), // 
    event(test("dynamic-test:#1", "succeedingTest"), started()), // 
    event(test("dynamic-test:#1", "succeedingTest"), finishedSuccessfully()), // 
    event(dynamicTestRegistered("dynamic-test:#2")), // 
    event(test("dynamic-test:#2", "failingTest"), started()), // 
    event(test("dynamic-test:#2", "failingTest"), finishedWithFailure(message("failing"))), // 
    event(container("dynamic-container:#1"), finishedSuccessfully()), // 
    event(container("dynamicContainerWithIterable"), finishedSuccessfully()), // 
    event(container(MyDynamicTestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
    Events containers = executionResults.containerEvents();
    Events tests = executionResults.testEvents();
    assertAll(() -> assertEquals(4, containers.started().count(), "# container started"), () -> assertEquals(1, containers.dynamicallyRegistered().count(), "# dynamic containers registered"), () -> assertEquals(2, tests.dynamicallyRegistered().count(), "# dynamic tests registered"), () -> assertEquals(2, tests.started().count(), "# tests started"), () -> assertEquals(1, tests.succeeded().count(), "# tests succeeded"), () -> assertEquals(1, tests.failed().count(), "# tests failed"), () -> assertEquals(4, containers.finished().count(), "# container finished"));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Events(org.junit.platform.testkit.engine.Events) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 30 with EngineExecutionResults

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

the class DynamicNodeGenerationTests method nestedDynamicContainersAreExecuted.

@Test
void nestedDynamicContainersAreExecuted() {
    EngineExecutionResults executionResults = executeTests(selectMethod(MyDynamicTestCase.class, "nestedDynamicContainers"));
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(MyDynamicTestCase.class), started()), // 
    event(container("nestedDynamicContainers"), started()), // 
    event(dynamicTestRegistered(displayName("gift wrap"))), // 
    event(container(displayName("gift wrap")), started()), // 
    event(dynamicTestRegistered(displayName("box"))), // 
    event(container(displayName("box")), started()), // 
    event(dynamicTestRegistered("dynamic-test:#1")), // 
    event(test("dynamic-test:#1", "succeedingTest"), started()), // 
    event(test("dynamic-test:#1", "succeedingTest"), finishedSuccessfully()), // 
    event(dynamicTestRegistered("dynamic-test:#2")), // 
    event(test("dynamic-test:#2", "failingTest"), started()), // 
    event(test("dynamic-test:#2", "failingTest"), finishedWithFailure(message("failing"))), // 
    event(container(displayName("box")), finishedSuccessfully()), // 
    event(container(displayName("gift wrap")), finishedSuccessfully()), // 
    event(container("nestedDynamicContainers"), finishedSuccessfully()), // 
    event(container(MyDynamicTestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
    Events containers = executionResults.containerEvents();
    Events tests = executionResults.testEvents();
    assertAll(() -> assertEquals(5, containers.started().count(), "# container started"), () -> assertEquals(2, containers.dynamicallyRegistered().count(), "# dynamic containers registered"), () -> assertEquals(2, tests.dynamicallyRegistered().count(), "# dynamic tests registered"), () -> assertEquals(2, tests.started().count(), "# tests started"), () -> assertEquals(1, tests.succeeded().count(), "# tests succeeded"), () -> assertEquals(1, tests.failed().count(), "# tests failed"), () -> assertEquals(5, containers.finished().count(), "# container finished"));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Events(org.junit.platform.testkit.engine.Events) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

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