Search in sources :

Example 56 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TestExecutionExceptionHandlerTests method exceptionHandlerRethrowsException.

@Test
void exceptionHandlerRethrowsException() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(ATestCase.class, "testRethrow")).build();
    EngineExecutionResults executionResults = executeTests(request);
    assertTrue(RethrowException.handleExceptionCalled, "TestExecutionExceptionHandler should have been called");
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(ATestCase.class), started()), // 
    event(test("testRethrow"), started()), // 
    event(test("testRethrow"), finishedWithFailure(instanceOf(IOException.class), message("checked"))), // 
    event(container(ATestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 57 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TestInstanceFactoryTests method multipleFactoriesRegisteredOnSingleTestClass.

@Test
void multipleFactoriesRegisteredOnSingleTestClass() {
    Class<?> testClass = MultipleFactoriesRegisteredOnSingleTestCase.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(ExtensionConfigurationException.class), message("The following TestInstanceFactory extensions were registered for test class [" + testClass.getName() + "], but only one is permitted: " + // 
    nullSafeToString(FooInstanceFactory.class, BarInstanceFactory.class)))), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) Test(org.junit.jupiter.api.Test)

Example 58 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults 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()));
}
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 59 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TestInstanceFactoryTests method multipleFactoriesRegisteredWithinNestedClassStructure.

@Test
void multipleFactoriesRegisteredWithinNestedClassStructure() {
    Class<?> outerClass = MultipleFactoriesRegisteredWithinNestedClassStructureTestCase.class;
    Class<?> nestedClass = MultipleFactoriesRegisteredWithinNestedClassStructureTestCase.InnerTestCase.class;
    EngineExecutionResults executionResults = executeTestsForClass(outerClass);
    assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(1, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(outerClass), started()), // 
    event(test("outerTest()"), started()), // 
    event(test("outerTest()"), finishedSuccessfully()), // 
    event(nestedContainer(nestedClass), started()), event(nestedContainer(nestedClass), finishedWithFailure(instanceOf(ExtensionConfigurationException.class), message("The following TestInstanceFactory extensions were registered for test class [" + nestedClass.getName() + "], but only one is permitted: " + // 
    nullSafeToString(FooInstanceFactory.class, BarInstanceFactory.class)))), // 
    event(container(outerClass), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) Test(org.junit.jupiter.api.Test)

Example 60 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TestInstanceFactoryTests method instanceFactoryRegisteredAsLambdaExpression.

@Test
void instanceFactoryRegisteredAsLambdaExpression() {
    EngineExecutionResults executionResults = executeTestsForClass(LambdaFactoryTestCase.class);
    assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(1, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    // @formatter:off
    assertThat(callSequence).containsExactly("beforeEach: lambda", "test: lambda");
// @formatter:on
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) 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