Search in sources :

Example 41 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class DynamicNodeGenerationTests method dynamicContainersAreExecutedFromIterable.

@Test
void dynamicContainersAreExecutedFromIterable() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(MyDynamicTestCase.class, "dynamicContainerWithIterable")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    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()));
    assertAll(() -> assertEquals(4, eventRecorder.getContainerStartedCount(), "# container started"), () -> assertEquals(3, eventRecorder.getDynamicTestRegisteredCount(), "# dynamic tests registered"), () -> assertEquals(2, eventRecorder.getTestStartedCount(), "# tests started"), () -> assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded"), () -> assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed"), () -> assertEquals(4, eventRecorder.getContainerFinishedCount(), "# container finished"));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 42 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class DynamicNodeGenerationTests method nestedDynamicContainersAreExecuted.

@Test
void nestedDynamicContainersAreExecuted() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(MyDynamicTestCase.class, "nestedDynamicContainers")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    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()));
    assertAll(() -> assertEquals(5, eventRecorder.getContainerStartedCount(), "# container started"), () -> assertEquals(4, eventRecorder.getDynamicTestRegisteredCount(), "# dynamic tests registered"), () -> assertEquals(2, eventRecorder.getTestStartedCount(), "# tests started"), () -> assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded"), () -> assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed"), () -> assertEquals(5, eventRecorder.getContainerFinishedCount(), "# container finished"));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 43 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class DynamicNodeGenerationTests method dynamicTestsAreExecutedFromStream.

@Test
void dynamicTestsAreExecutedFromStream() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(MyDynamicTestCase.class, "dynamicStream")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    event(engine(), started()), // 
    event(container(MyDynamicTestCase.class), started()), // 
    event(container("dynamicStream"), 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("dynamicStream"), finishedSuccessfully()), // 
    event(container(MyDynamicTestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 44 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class ExceptionHandlingTests method checkedExceptionInAfterAllIsRegistered.

@Test
void checkedExceptionInAfterAllIsRegistered() throws NoSuchMethodException {
    Method method = FailureTestCase.class.getDeclaredMethod("succeedingTest");
    LauncherDiscoveryRequest request = request().selectors(selectMethod(FailureTestCase.class, method)).build();
    FailureTestCase.exceptionToThrowInAfterAll = Optional.of(new IOException("checked"));
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    event(engine(), started()), // 
    event(container(FailureTestCase.class), started()), // 
    event(test("succeedingTest"), started()), // 
    event(test("succeedingTest"), finishedSuccessfully()), event(container(FailureTestCase.class), // 
    finishedWithFailure(allOf(isA(IOException.class), message("checked")))), event(engine(), finishedSuccessfully()));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) Method(java.lang.reflect.Method) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 45 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class ExceptionHandlingTests method checkedExceptionInAfterEachIsSuppressedByExceptionInTest.

@Test
void checkedExceptionInAfterEachIsSuppressedByExceptionInTest() throws NoSuchMethodException {
    Method method = FailureTestCase.class.getDeclaredMethod("testWithUncheckedException");
    LauncherDiscoveryRequest request = request().selectors(selectMethod(FailureTestCase.class, method)).build();
    FailureTestCase.exceptionToThrowInAfterEach = Optional.of(new IOException("checked"));
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    event(engine(), started()), // 
    event(container(FailureTestCase.class), started()), // 
    event(test("testWithUncheckedException"), started()), event(// 
    test("testWithUncheckedException"), finishedWithFailure(allOf(// 
    isA(RuntimeException.class), // 
    message("unchecked"), // 
    suppressed(0, allOf(isA(IOException.class), message("checked")))))), // 
    event(container(FailureTestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) Method(java.lang.reflect.Method) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)167 Test (org.junit.jupiter.api.Test)141 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)74 TestDescriptor (org.junit.platform.engine.TestDescriptor)54 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)33 Launcher (org.junit.platform.launcher.Launcher)16 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)11 DiscoverySelectors.selectMethod (org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod)11 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)11 Method (java.lang.reflect.Method)10 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)8 IOException (java.io.IOException)7 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)7 ArrayList (java.util.ArrayList)6 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)6 TestIdentifier (org.junit.platform.launcher.TestIdentifier)5 TestPlan (org.junit.platform.launcher.TestPlan)5 Path (java.nio.file.Path)4 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)4