Search in sources :

Example 66 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class TestCaseWithInheritanceTests method beforeAndAfterMethodsInTestClassHierarchy.

@Test
void beforeAndAfterMethodsInTestClassHierarchy() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(TestCase3.class);
    // @formatter:off
    assertAll(() -> assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started"), () -> assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded"), () -> assertEquals(0, eventRecorder.getTestSkippedCount(), "# tests skipped"), () -> assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted"), () -> assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed"));
    // @formatter:on
    // @formatter:off
    assertEquals(asList("beforeAll1", "beforeAll2", "beforeAll3", "beforeEach1", "beforeEach2", "beforeEach3", "test3", "afterEach3", "afterEach2", "afterEach1", "afterAll3", "afterAll2", "afterAll1"), callSequence, "wrong call sequence");
// @formatter:on
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 67 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class TestCaseWithInheritanceTests method executeSingleTest.

@Test
void executeSingleTest() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(LocalTestCase.class, "alwaysPasses")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestSkippedCount(), "# tests skipped");
    assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted");
    assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 68 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class TestInstanceLifecycleKotlinTests method instancePerMethodIsDefaultForKotlinTestClasses.

@Test
void instancePerMethodIsDefaultForKotlinTestClasses() {
    Class<?> testClass = InstancePerMethodKotlinTestCase.class;
    InstancePerMethodKotlinTestCase.TEST_INSTANCES.clear();
    ExecutionEventRecorder eventRecorder = executeTestsForClass(testClass);
    assertThat(eventRecorder.getTestFinishedCount()).isEqualTo(2);
    List<Object> instances = new ArrayList<>(InstancePerMethodKotlinTestCase.TEST_INSTANCES.keySet());
    // 
    assertThat(instances).hasSize(// 
    3).extracting(// 
    o -> (Object) o.getClass()).containsExactly(// 
    InstancePerMethodKotlinTestCase.Companion.getClass(), // 
    InstancePerMethodKotlinTestCase.class, InstancePerMethodKotlinTestCase.class);
    // 
    assertThat(InstancePerMethodKotlinTestCase.TEST_INSTANCES.get(instances.get(0))).containsEntry("beforeAll", // 
    1).containsEntry("afterAll", 1);
    // 
    assertThat(InstancePerMethodKotlinTestCase.TEST_INSTANCES.get(instances.get(1))).containsEntry("beforeEach", // 
    1).containsEntry("test", // 
    1).containsEntry("afterEach", 1);
    // 
    assertThat(InstancePerMethodKotlinTestCase.TEST_INSTANCES.get(instances.get(2))).containsEntry("beforeEach", // 
    1).containsEntry("test", // 
    1).containsEntry("afterEach", 1);
}
Also used : InstancePerMethodKotlinTestCase(org.junit.jupiter.engine.kotlin.InstancePerMethodKotlinTestCase) Test(org.junit.jupiter.api.Test) CollectionUtils.getOnlyElement(org.junit.platform.commons.util.CollectionUtils.getOnlyElement) List(java.util.List) InstancePerClassKotlinTestCase(org.junit.jupiter.engine.kotlin.InstancePerClassKotlinTestCase) TestInstance(org.junit.jupiter.api.TestInstance) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InstancePerMethodKotlinTestCase(org.junit.jupiter.engine.kotlin.InstancePerMethodKotlinTestCase) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 69 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class TestInstanceLifecycleKotlinTests method instancePerClassCanBeUsedForKotlinTestClasses.

@Test
void instancePerClassCanBeUsedForKotlinTestClasses() {
    Class<?> testClass = InstancePerClassKotlinTestCase.class;
    InstancePerClassKotlinTestCase.TEST_INSTANCES.clear();
    ExecutionEventRecorder eventRecorder = executeTestsForClass(testClass);
    assertThat(eventRecorder.getTestFinishedCount()).isEqualTo(2);
    assertThat(InstancePerClassKotlinTestCase.TEST_INSTANCES.keySet()).hasSize(1);
    // 
    assertThat(getOnlyElement(InstancePerClassKotlinTestCase.TEST_INSTANCES.values())).containsEntry("beforeAll", // 
    1).containsEntry("beforeEach", // 
    2).containsEntry("test", // 
    2).containsEntry("afterEach", // 
    2).containsEntry("afterAll", 1);
}
Also used : InstancePerClassKotlinTestCase(org.junit.jupiter.engine.kotlin.InstancePerClassKotlinTestCase) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 70 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class TestInstanceLifecycleTests method performAssertions.

private void performAssertions(Class<?> testClass, int containers, int tests, Map.Entry<Class<?>, Integer>[] instanceCountEntries, int allMethods, int eachMethods) {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(testClass);
    // @formatter:off
    assertAll(() -> assertEquals(containers, eventRecorder.getContainerStartedCount(), "# containers started"), () -> assertEquals(containers, eventRecorder.getContainerFinishedCount(), "# containers finished"), () -> assertEquals(tests, eventRecorder.getTestStartedCount(), "# tests started"), () -> assertEquals(tests, eventRecorder.getTestSuccessfulCount(), "# tests succeeded"), () -> assertThat(instanceCount).describedAs("instance count").contains(instanceCountEntries), () -> assertEquals(allMethods, beforeAllCount, "@BeforeAll count"), () -> assertEquals(allMethods, afterAllCount, "@AfterAll count"), () -> assertEquals(eachMethods, beforeEachCount, "@BeforeEach count"), () -> assertEquals(eachMethods, afterEachCount, "@AfterEach count"));
// @formatter:on
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder)

Aggregations

ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)114 Test (org.junit.jupiter.api.Test)104 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)74 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)12 DiscoverySelectors.selectMethod (org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod)12 Method (java.lang.reflect.Method)10 TestDescriptor (org.junit.platform.engine.TestDescriptor)8 IOException (java.io.IOException)6 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 TestInfo (org.junit.jupiter.api.TestInfo)4 UniqueId (org.junit.platform.engine.UniqueId)4 JupiterTestEngine (org.junit.jupiter.engine.JupiterTestEngine)3 LauncherDiscoveryRequestBuilder.request (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request)3 Map (java.util.Map)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2 Assertions.allOf (org.assertj.core.api.Assertions.allOf)2