Search in sources :

Example 81 with ExecutionEventRecorder

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

the class ExceptionHandlingTests method checkedExceptionInAfterEachIsRegistered.

@Test
void checkedExceptionInAfterEachIsRegistered() throws NoSuchMethodException {
    Method method = FailureTestCase.class.getDeclaredMethod("succeedingTest");
    LauncherDiscoveryRequest request = request().selectors(selectMethod(FailureTestCase.class, method)).build();
    FailureTestCase.exceptionToThrowInAfterEach = Optional.of(new IOException("checked"));
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    assertRecordedExecutionEventsContainsExactly(eventRecorder.getFailedTestFinishedEvents(), event(test("succeedingTest"), finishedWithFailure(allOf(isA(IOException.class), message("checked")))));
}
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 82 with ExecutionEventRecorder

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

the class ExceptionHandlingTests method exceptionInAfterAllCallbackDoesNotHideFailureWhenTestInstancePerClassIsUsed.

@Test
void exceptionInAfterAllCallbackDoesNotHideFailureWhenTestInstancePerClassIsUsed() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(TestCaseWithInvalidConstructorAndThrowingAfterAllCallback.class)).build();
    FailureTestCase.exceptionToThrowInAfterAll = Optional.of(new IOException("after"));
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    event(engine(), started()), // 
    event(container(TestCaseWithInvalidConstructorAndThrowingAfterAllCallback.class), started()), event(container(TestCaseWithInvalidConstructorAndThrowingAfterAllCallback.class), finishedWithFailure(allOf(// 
    message(m -> m.contains("constructor")), // 
    suppressed(0, message("callback"))))), event(engine(), finishedSuccessfully()));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 83 with ExecutionEventRecorder

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

the class ExceptionHandlingTests method failureInTestMethodIsRegistered.

@Test
void failureInTestMethodIsRegistered() throws NoSuchMethodException {
    Method method = FailureTestCase.class.getDeclaredMethod("failingTest");
    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("failingTest"), finishedWithFailure(allOf(isA(AssertionFailedError.class), message("always fails")))));
}
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 84 with ExecutionEventRecorder

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

the class ExceptionHandlingTests method checkedExceptionInBeforeAllIsRegistered.

@Test
void checkedExceptionInBeforeAllIsRegistered() throws NoSuchMethodException {
    Method method = FailureTestCase.class.getDeclaredMethod("succeedingTest");
    LauncherDiscoveryRequest request = request().selectors(selectMethod(FailureTestCase.class, method)).build();
    FailureTestCase.exceptionToThrowInBeforeAll = Optional.of(new IOException("checked"));
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    event(engine(), started()), // 
    event(container(FailureTestCase.class), started()), 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 85 with ExecutionEventRecorder

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

the class ExceptionHandlingTests method checkedExceptionInBeforeEachIsRegistered.

@Test
void checkedExceptionInBeforeEachIsRegistered() throws NoSuchMethodException {
    Method method = FailureTestCase.class.getDeclaredMethod("succeedingTest");
    LauncherDiscoveryRequest request = request().selectors(selectMethod(FailureTestCase.class, method)).build();
    FailureTestCase.exceptionToThrowInBeforeEach = Optional.of(new IOException("checked"));
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    assertRecordedExecutionEventsContainsExactly(eventRecorder.getFailedTestFinishedEvents(), event(test("succeedingTest"), finishedWithFailure(allOf(isA(IOException.class), message("checked")))));
}
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

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