Search in sources :

Example 36 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder 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 37 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder 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)

Example 38 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class ExceptionHandlingTests method uncheckedExceptionInTestMethodIsRegistered.

@Test
void uncheckedExceptionInTestMethodIsRegistered() throws NoSuchMethodException {
    Method method = FailureTestCase.class.getDeclaredMethod("testWithUncheckedException");
    LauncherDiscoveryRequest request = request().selectors(selectMethod(FailureTestCase.class, method)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getFailedTestFinishedEvents(), event(test("testWithUncheckedException"), finishedWithFailure(allOf(isA(RuntimeException.class), message("unchecked")))));
}
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) Test(org.junit.jupiter.api.Test)

Example 39 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class NestedTestClassesTests method nestedTestsAreExecuted.

@Test
void nestedTestsAreExecuted() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(TestCaseWithNesting.class);
    assertEquals(3, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(2, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    assertEquals(3, eventRecorder.getContainerStartedCount(), "# containers started");
    assertEquals(3, eventRecorder.getContainerFinishedCount(), "# containers finished");
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 40 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class NestedTestClassesTests method doublyNestedTestsAreExecuted.

@Test
void doublyNestedTestsAreExecuted() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(TestCaseWithDoubleNesting.class);
    assertEquals(5, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(3, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(2, eventRecorder.getTestFailedCount(), "# tests failed");
    assertEquals(4, eventRecorder.getContainerStartedCount(), "# containers started");
    assertEquals(4, eventRecorder.getContainerFinishedCount(), "# containers finished");
    assertAll(// 
    "before each counts", () -> assertEquals(5, TestCaseWithDoubleNesting.beforeTopCount), () -> assertEquals(4, TestCaseWithDoubleNesting.beforeNestedCount), () -> assertEquals(2, TestCaseWithDoubleNesting.beforeDoublyNestedCount));
    assertAll(// 
    "after each counts", () -> assertEquals(5, TestCaseWithDoubleNesting.afterTopCount), () -> assertEquals(4, TestCaseWithDoubleNesting.afterNestedCount), () -> assertEquals(2, TestCaseWithDoubleNesting.afterDoublyNestedCount));
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)114 Test (org.junit.jupiter.api.Test)104 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)74 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)12 DiscoverySelectors.selectMethod (org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod)12 Method (java.lang.reflect.Method)10 TestDescriptor (org.junit.platform.engine.TestDescriptor)8 IOException (java.io.IOException)6 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 TestInfo (org.junit.jupiter.api.TestInfo)4 UniqueId (org.junit.platform.engine.UniqueId)4 JupiterTestEngine (org.junit.jupiter.engine.JupiterTestEngine)3 LauncherDiscoveryRequestBuilder.request (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request)3 Map (java.util.Map)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2 Assertions.allOf (org.assertj.core.api.Assertions.allOf)2