Search in sources :

Example 71 with EngineExecutionResults

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);
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 72 with EngineExecutionResults

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()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 73 with EngineExecutionResults

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()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) BeforeEach(org.junit.jupiter.api.BeforeEach) EventConditions.event(org.junit.platform.testkit.engine.EventConditions.event) EventConditions.nestedContainer(org.junit.platform.testkit.engine.EventConditions.nestedContainer) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EventConditions.finishedWithFailure(org.junit.platform.testkit.engine.EventConditions.finishedWithFailure) ClassUtils.nullSafeToString(org.junit.platform.commons.util.ClassUtils.nullSafeToString) EventConditions.finishedSuccessfully(org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully) TestExecutionResultConditions.message(org.junit.platform.testkit.engine.TestExecutionResultConditions.message) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Nested(org.junit.jupiter.api.Nested) ArrayList(java.util.ArrayList) EventConditions.container(org.junit.platform.testkit.engine.EventConditions.container) AfterAll(org.junit.jupiter.api.AfterAll) URLClassLoader(java.net.URLClassLoader) TestInstance(org.junit.jupiter.api.TestInstance) EventConditions.started(org.junit.platform.testkit.engine.EventConditions.started) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AbstractJupiterTestEngineTests(org.junit.jupiter.engine.AbstractJupiterTestEngineTests) EventConditions.test(org.junit.platform.testkit.engine.EventConditions.test) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) TestInstanceFactoryContext(org.junit.jupiter.api.extension.TestInstanceFactoryContext) TestInstantiationException(org.junit.jupiter.api.extension.TestInstantiationException) PER_CLASS(org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS) TestInstanceFactory(org.junit.jupiter.api.extension.TestInstanceFactory) ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) EventConditions.engine(org.junit.platform.testkit.engine.EventConditions.engine) Test(org.junit.jupiter.api.Test) List(java.util.List) TestExecutionResultConditions.instanceOf(org.junit.platform.testkit.engine.TestExecutionResultConditions.instanceOf) TestInstantiationException(org.junit.jupiter.api.extension.TestInstantiationException) Test(org.junit.jupiter.api.Test)

Example 74 with EngineExecutionResults

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()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) BeforeEach(org.junit.jupiter.api.BeforeEach) EventConditions.event(org.junit.platform.testkit.engine.EventConditions.event) EventConditions.nestedContainer(org.junit.platform.testkit.engine.EventConditions.nestedContainer) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EventConditions.finishedWithFailure(org.junit.platform.testkit.engine.EventConditions.finishedWithFailure) ClassUtils.nullSafeToString(org.junit.platform.commons.util.ClassUtils.nullSafeToString) EventConditions.finishedSuccessfully(org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully) TestExecutionResultConditions.message(org.junit.platform.testkit.engine.TestExecutionResultConditions.message) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Nested(org.junit.jupiter.api.Nested) ArrayList(java.util.ArrayList) EventConditions.container(org.junit.platform.testkit.engine.EventConditions.container) AfterAll(org.junit.jupiter.api.AfterAll) URLClassLoader(java.net.URLClassLoader) TestInstance(org.junit.jupiter.api.TestInstance) EventConditions.started(org.junit.platform.testkit.engine.EventConditions.started) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AbstractJupiterTestEngineTests(org.junit.jupiter.engine.AbstractJupiterTestEngineTests) EventConditions.test(org.junit.platform.testkit.engine.EventConditions.test) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) TestInstanceFactoryContext(org.junit.jupiter.api.extension.TestInstanceFactoryContext) TestInstantiationException(org.junit.jupiter.api.extension.TestInstantiationException) PER_CLASS(org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS) TestInstanceFactory(org.junit.jupiter.api.extension.TestInstanceFactory) ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) EventConditions.engine(org.junit.platform.testkit.engine.EventConditions.engine) Test(org.junit.jupiter.api.Test) List(java.util.List) TestExecutionResultConditions.instanceOf(org.junit.platform.testkit.engine.TestExecutionResultConditions.instanceOf) TestInstantiationException(org.junit.jupiter.api.extension.TestInstantiationException) Test(org.junit.jupiter.api.Test)

Example 75 with EngineExecutionResults

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()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) BeforeEach(org.junit.jupiter.api.BeforeEach) EventConditions.event(org.junit.platform.testkit.engine.EventConditions.event) EventConditions.nestedContainer(org.junit.platform.testkit.engine.EventConditions.nestedContainer) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EventConditions.finishedWithFailure(org.junit.platform.testkit.engine.EventConditions.finishedWithFailure) ClassUtils.nullSafeToString(org.junit.platform.commons.util.ClassUtils.nullSafeToString) EventConditions.finishedSuccessfully(org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully) TestExecutionResultConditions.message(org.junit.platform.testkit.engine.TestExecutionResultConditions.message) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Nested(org.junit.jupiter.api.Nested) ArrayList(java.util.ArrayList) EventConditions.container(org.junit.platform.testkit.engine.EventConditions.container) AfterAll(org.junit.jupiter.api.AfterAll) URLClassLoader(java.net.URLClassLoader) TestInstance(org.junit.jupiter.api.TestInstance) EventConditions.started(org.junit.platform.testkit.engine.EventConditions.started) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AbstractJupiterTestEngineTests(org.junit.jupiter.engine.AbstractJupiterTestEngineTests) EventConditions.test(org.junit.platform.testkit.engine.EventConditions.test) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) TestInstanceFactoryContext(org.junit.jupiter.api.extension.TestInstanceFactoryContext) TestInstantiationException(org.junit.jupiter.api.extension.TestInstantiationException) PER_CLASS(org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS) TestInstanceFactory(org.junit.jupiter.api.extension.TestInstanceFactory) ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) EventConditions.engine(org.junit.platform.testkit.engine.EventConditions.engine) Test(org.junit.jupiter.api.Test) List(java.util.List) TestExecutionResultConditions.instanceOf(org.junit.platform.testkit.engine.TestExecutionResultConditions.instanceOf) TestInstantiationException(org.junit.jupiter.api.extension.TestInstantiationException) Test(org.junit.jupiter.api.Test)

Aggregations

EngineExecutionResults (org.junit.platform.testkit.engine.EngineExecutionResults)139 Test (org.junit.jupiter.api.Test)134 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)32 DynamicTest (org.junit.jupiter.api.DynamicTest)30 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)30 Events (org.junit.platform.testkit.engine.Events)27 DisplayName (org.junit.jupiter.api.DisplayName)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)15 IOException (java.io.IOException)12 Execution (org.junit.platform.testkit.engine.Execution)12 TimeoutException (java.util.concurrent.TimeoutException)10 List (java.util.List)8 ExtensionConfigurationException (org.junit.jupiter.api.extension.ExtensionConfigurationException)8 ArrayList (java.util.ArrayList)7 AfterAll (org.junit.jupiter.api.AfterAll)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 BeforeAll (org.junit.jupiter.api.BeforeAll)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Nested (org.junit.jupiter.api.Nested)7 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)7