Search in sources :

Example 46 with ExecutionEventRecorder

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

the class TestCaseWithInheritanceTests method executeTestDeclaredInSuperClass.

@Test
void executeTestDeclaredInSuperClass() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(LocalTestCase.class, "superTest")).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");
    assertEquals(1, LocalTestCase.countBeforeInvoked, "# after calls");
    assertEquals(1, LocalTestCase.countAfterInvoked, "# after calls");
    assertEquals(1, AbstractTestCase.countSuperBeforeInvoked, "# super before calls");
    assertEquals(1, AbstractTestCase.countSuperAfterInvoked, "# super after calls");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 47 with ExecutionEventRecorder

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

the class TestCaseWithInheritanceTests method executeTestWithExceptionThrownInAfterMethod.

@Test
void executeTestWithExceptionThrownInAfterMethod() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(LocalTestCase.class, "throwExceptionInAfterMethod")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(0, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestSkippedCount(), "# tests skipped");
    assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted");
    assertEquals(1, 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 48 with ExecutionEventRecorder

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

the class TestInstanceLifecycleConfigurationTests method performAssertions.

private void performAssertions(Class<?> testClass, Map<String, String> configParams, int containers, int failedContainers, int tests, String... methods) {
    // @formatter:off
    ExecutionEventRecorder eventRecorder = executeTests(request().selectors(selectClass(testClass)).configurationParameters(configParams).build());
    assertAll(() -> assertEquals(containers, eventRecorder.getContainerStartedCount(), "# containers started"), () -> assertEquals(containers, eventRecorder.getContainerFinishedCount(), "# containers finished"), () -> assertEquals(failedContainers, eventRecorder.getContainerFailedCount(), "# containers failed"), () -> assertEquals(tests, eventRecorder.getTestStartedCount(), "# tests started"), () -> assertEquals(tests, eventRecorder.getTestSuccessfulCount(), "# tests succeeded"), () -> assertEquals(Arrays.asList(methods), methodsInvoked));
// @formatter:on
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder)

Example 49 with ExecutionEventRecorder

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

the class TestTemplateInvocationTests method templateWithTwoInvocationsFromSingleExtensionIsInvoked.

@Test
void templateWithTwoInvocationsFromSingleExtensionIsInvoked() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(MyTestTemplateTestCase.class, "templateWithTwoInvocationsFromSingleExtension")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), wrappedInContainerEvents(// 
    MyTestTemplateTestCase.class, // 
    event(container("templateWithTwoInvocationsFromSingleExtension"), started()), // 
    event(dynamicTestRegistered("test-template-invocation:#1"), displayName("[1]")), // 
    event(test("test-template-invocation:#1"), started()), event(test("test-template-invocation:#1"), // 
    finishedWithFailure(message("invocation is expected to fail"))), // 
    event(dynamicTestRegistered("test-template-invocation:#2"), displayName("[2]")), // 
    event(test("test-template-invocation:#2"), started()), event(test("test-template-invocation:#2"), // 
    finishedWithFailure(message("invocation is expected to fail"))), event(container("templateWithTwoInvocationsFromSingleExtension"), finishedSuccessfully())));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 50 with ExecutionEventRecorder

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

the class TestTemplateInvocationTests method disabledTemplateIsSkipped.

@Test
void disabledTemplateIsSkipped() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(MyTestTemplateTestCase.class, "disabledTemplate")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), wrappedInContainerEvents(// 
    MyTestTemplateTestCase.class, event(container("disabledTemplate"), skippedWithReason("always disabled"))));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

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