Search in sources :

Example 76 with EngineExecutionResults

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

the class TestInstanceFactoryTests method inheritedFactoryInTestClassHierarchy.

@Test
void inheritedFactoryInTestClassHierarchy() {
    EngineExecutionResults executionResults = executeTestsForClass(InheritedFactoryTestCase.class);
    assertEquals(2, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(2, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    // @formatter:off
    assertThat(callSequence).containsExactly("FooInstanceFactory instantiated: InheritedFactoryTestCase", "parentTest", "FooInstanceFactory instantiated: InheritedFactoryTestCase", "childTest");
// @formatter:on
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Test(org.junit.jupiter.api.Test)

Example 77 with EngineExecutionResults

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

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

the class TestInstanceFactoryTests method instanceFactoryWithPerClassLifecycle.

@Test
void instanceFactoryWithPerClassLifecycle() {
    EngineExecutionResults executionResults = executeTestsForClass(PerClassLifecycleTestCase.class);
    assertEquals(1, PerClassLifecycleTestCase.counter.get());
    assertEquals(2, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(2, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    // @formatter:off
    assertThat(callSequence).containsExactly("FooInstanceFactory instantiated: PerClassLifecycleTestCase", "@BeforeAll", "@BeforeEach", "test1", "@BeforeEach", "test2", "@AfterAll");
// @formatter:on
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Test(org.junit.jupiter.api.Test)

Example 79 with EngineExecutionResults

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

the class TestInstanceFactoryTests method instanceFactoryRegisteredViaTestInterface.

@Test
void instanceFactoryRegisteredViaTestInterface() {
    EngineExecutionResults executionResults = executeTestsForClass(FactoryFromInterfaceTestCase.class);
    assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(1, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    // @formatter:off
    assertThat(callSequence).containsExactly("FooInstanceFactory instantiated: FactoryFromInterfaceTestCase", "test");
// @formatter:on
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Test(org.junit.jupiter.api.Test)

Example 80 with EngineExecutionResults

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

the class TestInstanceFactoryTests method instanceFactoriesInNestedClassStructureAreInherited.

@Test
void instanceFactoriesInNestedClassStructureAreInherited() {
    EngineExecutionResults executionResults = executeTestsForClass(OuterTestCase.class);
    assertEquals(3, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(3, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    // @formatter:off
    assertThat(callSequence).containsExactly(// OuterTestCase
    "FooInstanceFactory instantiated: OuterTestCase", "outerTest", // InnerTestCase
    "FooInstanceFactory instantiated: OuterTestCase", "FooInstanceFactory instantiated: InnerTestCase", "innerTest1", // InnerInnerTestCase
    "FooInstanceFactory instantiated: OuterTestCase", "FooInstanceFactory instantiated: InnerTestCase", "FooInstanceFactory instantiated: InnerInnerTestCase", "innerTest2");
// @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