use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.
the class TestExecutionExceptionHandlerTests method severalHandlersAreCalledInOrder.
@Test
void severalHandlersAreCalledInOrder() {
LauncherDiscoveryRequest request = request().selectors(selectMethod(ATestCase.class, "testSeveral")).build();
EngineExecutionResults executionResults = executeTests(request);
assertTrue(ConvertException.handleExceptionCalled, "ConvertException should have been called");
assertTrue(RethrowException.handleExceptionCalled, "RethrowException should have been called");
assertTrue(SwallowException.handleExceptionCalled, "SwallowException should have been called");
assertFalse(ShouldNotBeCalled.handleExceptionCalled, "ShouldNotBeCalled should not have been called");
//
executionResults.allEvents().assertEventsMatchExactly(//
event(engine(), started()), //
event(container(ATestCase.class), started()), //
event(test("testSeveral"), started()), //
event(test("testSeveral"), finishedSuccessfully()), //
event(container(ATestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
assertEquals(Arrays.asList("convert", "rethrow", "swallow"), handlerCalls);
}
use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.
the class TestExecutionExceptionHandlerTests method exceptionHandlerSwallowsException.
@Test
void exceptionHandlerSwallowsException() {
LauncherDiscoveryRequest request = request().selectors(selectMethod(ATestCase.class, "testSwallow")).build();
EngineExecutionResults executionResults = executeTests(request);
assertTrue(SwallowException.handleExceptionCalled, "TestExecutionExceptionHandler should have been called");
//
executionResults.allEvents().assertEventsMatchExactly(//
event(engine(), started()), //
event(container(ATestCase.class), started()), //
event(test("testSwallow"), started()), //
event(test("testSwallow"), finishedSuccessfully()), //
event(container(ATestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.
the class TestInstanceFactoryTests method proxyTestInstanceFactoryFailsDueToUseOfDifferentClassLoader.
@Test
void proxyTestInstanceFactoryFailsDueToUseOfDifferentClassLoader() {
Class<?> testClass = ProxiedTestCase.class;
EngineExecutionResults executionResults = executeTestsForClass(testClass);
assertEquals(0, executionResults.testEvents().started().count(), "# tests started");
assertEquals(0, executionResults.testEvents().failed().count(), "# tests aborted");
//
executionResults.allEvents().assertEventsMatchExactly(//
event(engine(), started()), //
event(container(testClass), started()), event(//
container(testClass), // loaded by the different ClassLoader.
finishedWithFailure(instanceOf(TestInstantiationException.class), message(m -> m.startsWith("TestInstanceFactory [" + ProxyTestInstanceFactory.class.getName() + "]") && m.contains("failed to return an instance of [" + testClass.getName() + "@" + Integer.toHexString(System.identityHashCode(testClass))) && //
m.contains("and instead returned an instance of [" + testClass.getName() + "@")))), event(engine(), finishedSuccessfully()));
}
use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.
the class TestInstanceFactoryTests method nullTestInstanceFactoryWithPerClassLifecycle.
@Test
void nullTestInstanceFactoryWithPerClassLifecycle() {
Class<?> testClass = PerClassLifecycleNullTestInstanceFactoryTestCase.class;
EngineExecutionResults executionResults = executeTestsForClass(testClass);
assertEquals(0, executionResults.testEvents().started().count(), "# tests started");
assertEquals(0, executionResults.testEvents().failed().count(), "# tests aborted");
//
executionResults.allEvents().assertEventsMatchExactly(//
event(engine(), started()), //
event(container(testClass), started()), event(container(testClass), finishedWithFailure(instanceOf(TestInstantiationException.class), message(m -> m.equals("TestInstanceFactory [" + NullTestInstanceFactory.class.getName() + "] failed to return an instance of [" + testClass.getName() + //
"] and instead returned an instance of [null].")))), event(engine(), finishedSuccessfully()));
}
use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.
the class TestInstanceFactoryTests method bogusTestInstanceFactoryWithPerClassLifecycle.
@Test
void bogusTestInstanceFactoryWithPerClassLifecycle() {
Class<?> testClass = PerClassLifecycleBogusTestInstanceFactoryTestCase.class;
EngineExecutionResults executionResults = executeTestsForClass(testClass);
assertEquals(0, executionResults.testEvents().started().count(), "# tests started");
assertEquals(0, executionResults.testEvents().failed().count(), "# tests aborted");
//
executionResults.allEvents().assertEventsMatchExactly(//
event(engine(), started()), //
event(container(testClass), started()), event(container(testClass), finishedWithFailure(instanceOf(TestInstantiationException.class), message(m -> m.equals("TestInstanceFactory [" + BogusTestInstanceFactory.class.getName() + "] failed to return an instance of [" + testClass.getName() + //
"] and instead returned an instance of [java.lang.String].")))), event(engine(), finishedSuccessfully()));
}
Aggregations