Search in sources :

Example 51 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class ParameterResolverTests method executeTestsForMethodInjectionInBeforeAndAfterAllMethods.

@Test
void executeTestsForMethodInjectionInBeforeAndAfterAllMethods() {
    EngineExecutionResults executionResults = executeTestsForClass(BeforeAndAfterAllMethodInjectionTestCase.class);
    assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(1, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    assertEquals(0, executionResults.testEvents().skipped().count(), "# tests skipped");
    assertEquals(0, executionResults.testEvents().aborted().count(), "# tests aborted");
    assertEquals(0, executionResults.testEvents().failed().count(), "# tests failed");
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Test(org.junit.jupiter.api.Test)

Example 52 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class ParameterResolverTests method executeTestsForPrimitiveArrayMethodInjectionCases.

@Test
void executeTestsForPrimitiveArrayMethodInjectionCases() {
    EngineExecutionResults executionResults = executeTestsForClass(PrimitiveArrayMethodInjectionTestCase.class);
    assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(1, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    assertEquals(0, executionResults.testEvents().failed().count(), "# tests failed");
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Test(org.junit.jupiter.api.Test)

Example 53 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class ParameterResolverTests method executeTestsForPotentiallyIncompatibleTypeMethodInjectionCases.

@Test
void executeTestsForPotentiallyIncompatibleTypeMethodInjectionCases() {
    EngineExecutionResults executionResults = executeTestsForClass(PotentiallyIncompatibleTypeMethodInjectionTestCase.class);
    Events tests = executionResults.testEvents();
    assertEquals(3, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(2, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    assertEquals(1, executionResults.testEvents().failed().count(), "# 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");
    tests.failed().assertEventsMatchExactly(event(test("doubleParameterInjection"), finishedWithFailure(instanceOf(ParameterResolutionException.class), message(expectations))));
// @formatter:on
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) 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) Events(org.junit.platform.testkit.engine.Events) EventConditions.event(org.junit.platform.testkit.engine.EventConditions.event) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) EventConditions.finishedWithFailure(org.junit.platform.testkit.engine.EventConditions.finishedWithFailure) CustomType(org.junit.jupiter.engine.execution.injection.sample.CustomType) NumberParameterResolver(org.junit.jupiter.engine.execution.injection.sample.NumberParameterResolver) TestExecutionResultConditions.message(org.junit.platform.testkit.engine.TestExecutionResultConditions.message) Disabled(org.junit.jupiter.api.Disabled) 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) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) EventConditions.test(org.junit.platform.testkit.engine.EventConditions.test) MapOfListsTypeBasedParameterResolver(org.junit.jupiter.engine.execution.injection.sample.MapOfListsTypeBasedParameterResolver) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Method(java.lang.reflect.Method) EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) MapOfStringsParameterResolver(org.junit.jupiter.engine.execution.injection.sample.MapOfStringsParameterResolver) Predicate(java.util.function.Predicate) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) PrimitiveIntegerParameterResolver(org.junit.jupiter.engine.execution.injection.sample.PrimitiveIntegerParameterResolver) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) 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) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TestExecutionResultConditions.instanceOf(org.junit.platform.testkit.engine.TestExecutionResultConditions.instanceOf) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CustomAnnotation(org.junit.jupiter.engine.execution.injection.sample.CustomAnnotation) ParameterResolver(org.junit.jupiter.api.extension.ParameterResolver) Events(org.junit.platform.testkit.engine.Events) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) Test(org.junit.jupiter.api.Test)

Example 54 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TempDirectoryParameterResolverTests method testTempDirType.

@Test
@DisplayName("Test good and bad @TempDir parameters")
void testTempDirType() {
    EngineExecutionResults executionResults = executeTestsForClass(ATestCase.class);
    Events tests = executionResults.testEvents();
    tests.assertStatistics(stats -> stats.started(2).failed(1).succeeded(1));
    tests.succeeded().assertEventsMatchExactly(event(test("testGoodTempDirType"), finishedSuccessfully()));
    tests.failed().assertEventsMatchExactly(event(test("testBadTempDirType"), finishedWithFailure(instanceOf(ParameterResolutionException.class), message("Failed to resolve parameter [java.lang.String badTempDir] in method [void org.junit.jupiter.engine.extension.TempDirectoryParameterResolverTests$ATestCase.testBadTempDirType(java.lang.String)]: Can only resolve @TempDir parameter of type java.nio.file.Path or java.io.File but was: java.lang.String"))));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Events(org.junit.platform.testkit.engine.Events) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 55 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class TestExecutionExceptionHandlerTests method exceptionHandlerConvertsException.

@Test
void exceptionHandlerConvertsException() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(ATestCase.class, "testConvert")).build();
    EngineExecutionResults executionResults = executeTests(request);
    assertTrue(ConvertException.handleExceptionCalled, "TestExecutionExceptionHandler should have been called");
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(ATestCase.class), started()), // 
    event(test("testConvert"), started()), // 
    event(test("testConvert"), finishedWithFailure(instanceOf(IOException.class), message("checked"))), // 
    event(container(ATestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

EngineExecutionResults (org.junit.platform.testkit.engine.EngineExecutionResults)139 Test (org.junit.jupiter.api.Test)134 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)32 DynamicTest (org.junit.jupiter.api.DynamicTest)30 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)30 Events (org.junit.platform.testkit.engine.Events)27 DisplayName (org.junit.jupiter.api.DisplayName)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)15 IOException (java.io.IOException)12 Execution (org.junit.platform.testkit.engine.Execution)12 TimeoutException (java.util.concurrent.TimeoutException)10 List (java.util.List)8 ExtensionConfigurationException (org.junit.jupiter.api.extension.ExtensionConfigurationException)8 ArrayList (java.util.ArrayList)7 AfterAll (org.junit.jupiter.api.AfterAll)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 BeforeAll (org.junit.jupiter.api.BeforeAll)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Nested (org.junit.jupiter.api.Nested)7 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)7