use of org.junit.jupiter.api.extension.TestInstanceFactory in project junit5 by junit-team.
the class TestInstanceFactoryTests method nullTestInstanceFactoryWithPerMethodLifecycle.
@Test
void nullTestInstanceFactoryWithPerMethodLifecycle() {
Class<?> testClass = NullTestInstanceFactoryTestCase.class;
EngineExecutionResults executionResults = executeTestsForClass(testClass);
assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
assertEquals(1, executionResults.testEvents().failed().count(), "# tests aborted");
//
executionResults.allEvents().assertEventsMatchExactly(//
event(engine(), started()), //
event(container(testClass), started()), //
event(test("testShouldNotBeCalled"), started()), event(test("testShouldNotBeCalled"), 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(container(testClass), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
use of org.junit.jupiter.api.extension.TestInstanceFactory 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.jupiter.api.extension.TestInstanceFactory 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.jupiter.api.extension.TestInstanceFactory 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()));
}
use of org.junit.jupiter.api.extension.TestInstanceFactory in project junit5 by junit-team.
the class TestInstanceFactoryTests method bogusTestInstanceFactoryWithPerMethodLifecycle.
@Test
void bogusTestInstanceFactoryWithPerMethodLifecycle() {
Class<?> testClass = BogusTestInstanceFactoryTestCase.class;
EngineExecutionResults executionResults = executeTestsForClass(testClass);
assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
assertEquals(1, executionResults.testEvents().failed().count(), "# tests aborted");
//
executionResults.allEvents().assertEventsMatchExactly(//
event(engine(), started()), //
event(container(testClass), started()), //
event(test("testShouldNotBeCalled"), started()), event(test("testShouldNotBeCalled"), 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(container(testClass), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Aggregations