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")))));
}
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()));
}
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")))));
}
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()));
}
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")))));
}
Aggregations