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
}
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");
}
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);
}
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);
}
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
}
Aggregations