Search in sources :

Example 6 with ExecutionEventRecorder

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

the class ParameterResolverTests method executeTestsForPrimitiveIntegerMethodInjectionCases.

@Test
void executeTestsForPrimitiveIntegerMethodInjectionCases() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(PrimitiveIntegerMethodInjectionTestCase.class);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed");
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 7 with ExecutionEventRecorder

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

the class ParameterResolverTests method executeTestsForPotentiallyIncompatibleTypeMethodInjectionCases.

@Test
void executeTestsForPotentiallyIncompatibleTypeMethodInjectionCases() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(PotentiallyIncompatibleTypeMethodInjectionTestCase.class);
    assertEquals(3, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(2, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    Predicate<String> expectations = s -> s.contains("NumberParameterResolver") && s.contains("resolved a value of type [java.lang.Integer]") && s.contains("but a value assignment compatible with [java.lang.Double] is required");
    assertRecordedExecutionEventsContainsExactly(eventRecorder.getFailedTestFinishedEvents(), event(test("doubleParameterInjection"), finishedWithFailure(allOf(isA(ParameterResolutionException.class), message(expectations)))));
// @formatter:on
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) BeforeEach(org.junit.jupiter.api.BeforeEach) CustomTypeParameterResolver(org.junit.jupiter.engine.execution.injection.sample.CustomTypeParameterResolver) ExecutionEventConditions.assertRecordedExecutionEventsContainsExactly(org.junit.platform.engine.test.event.ExecutionEventConditions.assertRecordedExecutionEventsContainsExactly) Assertions.allOf(org.assertj.core.api.Assertions.allOf) ExecutionEventConditions.test(org.junit.platform.engine.test.event.ExecutionEventConditions.test) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CustomType(org.junit.jupiter.engine.execution.injection.sample.CustomType) NumberParameterResolver(org.junit.jupiter.engine.execution.injection.sample.NumberParameterResolver) Disabled(org.junit.jupiter.api.Disabled) TestExecutionResultConditions.isA(org.junit.platform.engine.test.event.TestExecutionResultConditions.isA) Nested(org.junit.jupiter.api.Nested) JupiterTestEngine(org.junit.jupiter.engine.JupiterTestEngine) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CustomAnnotationParameterResolver(org.junit.jupiter.engine.execution.injection.sample.CustomAnnotationParameterResolver) BeforeAll(org.junit.jupiter.api.BeforeAll) AbstractJupiterTestEngineTests(org.junit.jupiter.engine.AbstractJupiterTestEngineTests) PrimitiveArrayParameterResolver(org.junit.jupiter.engine.execution.injection.sample.PrimitiveArrayParameterResolver) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JAVA_8(org.junit.jupiter.api.condition.JRE.JAVA_8) DisabledOnJre(org.junit.jupiter.api.condition.DisabledOnJre) Method(java.lang.reflect.Method) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) ExecutionEventConditions.event(org.junit.platform.engine.test.event.ExecutionEventConditions.event) MapOfStringsParameterResolver(org.junit.jupiter.engine.execution.injection.sample.MapOfStringsParameterResolver) Predicate(java.util.function.Predicate) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) ExecutionEventConditions.finishedWithFailure(org.junit.platform.engine.test.event.ExecutionEventConditions.finishedWithFailure) PrimitiveIntegerParameterResolver(org.junit.jupiter.engine.execution.injection.sample.PrimitiveIntegerParameterResolver) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) TestExecutionResultConditions.message(org.junit.platform.engine.test.event.TestExecutionResultConditions.message) TestInfo(org.junit.jupiter.api.TestInfo) NullIntegerParameterResolver(org.junit.jupiter.engine.execution.injection.sample.NullIntegerParameterResolver) DisplayName(org.junit.jupiter.api.DisplayName) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CustomAnnotation(org.junit.jupiter.engine.execution.injection.sample.CustomAnnotation) ParameterResolver(org.junit.jupiter.api.extension.ParameterResolver) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 8 with ExecutionEventRecorder

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

the class TestExecutionExceptionHandlerTests method exceptionHandlerConvertsException.

@Test
void exceptionHandlerConvertsException() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(ATestCase.class, "testConvert")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertTrue(ConvertException.handleExceptionCalled, "TestExecutionExceptionHandler should have been called");
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    event(engine(), started()), // 
    event(container(ATestCase.class), started()), // 
    event(test("testConvert"), started()), // 
    event(test("testConvert"), finishedWithFailure(allOf(isA(IOException.class), message("checked")))), // 
    event(container(ATestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 9 with ExecutionEventRecorder

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

the class TestExecutionExceptionHandlerTests method exceptionHandlerRethrowsException.

@Test
void exceptionHandlerRethrowsException() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(ATestCase.class, "testRethrow")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertTrue(RethrowException.handleExceptionCalled, "TestExecutionExceptionHandler should have been called");
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    event(engine(), started()), // 
    event(container(ATestCase.class), started()), // 
    event(test("testRethrow"), started()), // 
    event(test("testRethrow"), finishedWithFailure(allOf(isA(IOException.class), message("checked")))), // 
    event(container(ATestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 10 with ExecutionEventRecorder

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

the class UniqueIdParsingForArrayParameterIntegrationTests method executeTestsForPrimitiveArrayMethodInjectionCases.

@Test
void executeTestsForPrimitiveArrayMethodInjectionCases() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(PrimitiveArrayMethodInjectionTestCase.class);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    UniqueId uniqueId = eventRecorder.getExecutionEvents().stream().map(ExecutionEvent::getTestDescriptor).distinct().skip(2).map(TestDescriptor::getUniqueId).findFirst().orElseThrow(AssertionError::new);
    // @formatter:on
    assertThat(UniqueId.parse(uniqueId.toString())).isEqualTo(uniqueId);
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) TestDescriptor(org.junit.platform.engine.TestDescriptor) 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