Search in sources :

Example 56 with ExecutionEventRecorder

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

the class TestTemplateInvocationTests method extensionIsAskedForSupportBeforeItMustProvide.

@Test
void extensionIsAskedForSupportBeforeItMustProvide() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(MyTestTemplateTestCase.class, "templateWithWrongParameterType", int.class.getName())).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), wrappedInContainerEvents(// 
    MyTestTemplateTestCase.class, // 
    event(container("templateWithWrongParameterType"), started()), event(container("templateWithWrongParameterType"), finishedWithFailure(message(s -> s.startsWith("You must register at least one TestTemplateInvocationContextProvider that supports @TestTemplate method ["))))));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 57 with ExecutionEventRecorder

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

the class TestTemplateInvocationTests method templateWithSupportingProviderButNoInvocationsReportsFailure.

@Test
void templateWithSupportingProviderButNoInvocationsReportsFailure() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(MyTestTemplateTestCase.class, "templateWithSupportingProviderButNoInvocations")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), wrappedInContainerEvents(// 
    MyTestTemplateTestCase.class, // 
    event(container("templateWithSupportingProviderButNoInvocations"), started()), event(container("templateWithSupportingProviderButNoInvocations"), finishedWithFailure(message("No supporting TestTemplateInvocationContextProvider provided an invocation context")))));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 58 with ExecutionEventRecorder

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

the class AtypicalJvmMethodNameTests method kotlinTestWithMethodNameContainingSpecialCharacters.

@Test
void kotlinTestWithMethodNameContainingSpecialCharacters() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(ArbitraryNamingKotlinTestCase.class);
    assertThat(eventRecorder.getTestFinishedCount()).isEqualTo(2);
    TestDescriptor testDescriptor1 = eventRecorder.getSuccessfulTestFinishedEvents().get(0).getTestDescriptor();
    assertAll(// 
    () -> assertEquals(METHOD_NAME + "()", testDescriptor1.getDisplayName()), () -> assertEquals(METHOD_NAME + "()", testDescriptor1.getLegacyReportingName()));
    TestDescriptor testDescriptor2 = eventRecorder.getSuccessfulTestFinishedEvents().get(1).getTestDescriptor();
    assertAll(// 
    () -> assertEquals("test name ends with parentheses()()", testDescriptor2.getDisplayName()), () -> assertEquals("test name ends with parentheses()()", testDescriptor2.getLegacyReportingName()));
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 59 with ExecutionEventRecorder

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

the class DefaultMethodTests method executeTestCaseWithOverloadedMethodNextToGenericDefaultMethodSelectedByClass.

@Test
void executeTestCaseWithOverloadedMethodNextToGenericDefaultMethodSelectedByClass() throws Exception {
    Class<?> clazz = GenericTestCaseWithDefaultMethod.class;
    LauncherDiscoveryRequest request = request().selectors(selectClass(clazz)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    // @formatter:off
    assertAll(() -> assertTrue(beforeAllInvoked, "@BeforeAll default method invoked from interface"), () -> assertTrue(afterAllInvoked, "@AfterAll default method invoked from interface"), () -> assertTrue(defaultMethodInvoked, "default @Test method invoked from interface"), () -> assertTrue(localMethodInvoked, "local @Test method invoked from class"), () -> assertEquals(2, eventRecorder.getTestStartedCount(), "# tests started"), () -> assertEquals(2, eventRecorder.getTestSuccessfulCount(), "# tests succeeded"), () -> assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed"));
// @formatter:on
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 60 with ExecutionEventRecorder

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

the class DefaultMethodTests method executeTestCaseWithDefaultMethodFromInterfaceSelectedByFullyQualifedMethodName.

@Test
void executeTestCaseWithDefaultMethodFromInterfaceSelectedByFullyQualifedMethodName() {
    String fqmn = TestCaseWithDefaultMethod.class.getName() + "#test";
    LauncherDiscoveryRequest request = request().selectors(selectMethod(fqmn)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    // @formatter:off
    assertAll(() -> assertTrue(beforeAllInvoked, "@BeforeAll static method invoked from interface"), () -> assertTrue(afterAllInvoked, "@AfterAll static method invoked from interface"), () -> assertTrue(defaultMethodInvoked, "default @Test method invoked from interface"), () -> assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started"), () -> assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded"), () -> assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed"));
// @formatter:on
}
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