Search in sources :

Example 46 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class ExceptionHandlingTests method uncheckedExceptionInTestMethodIsRegistered.

@Test
void uncheckedExceptionInTestMethodIsRegistered() throws NoSuchMethodException {
    Method method = FailureTestCase.class.getDeclaredMethod("testWithUncheckedException");
    LauncherDiscoveryRequest request = request().selectors(selectMethod(FailureTestCase.class, method)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getFailedTestFinishedEvents(), event(test("testWithUncheckedException"), finishedWithFailure(allOf(isA(RuntimeException.class), message("unchecked")))));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 47 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class NestedTestClassesTests method nestedTestsAreCorrectlyDiscovered.

@Test
void nestedTestsAreCorrectlyDiscovered() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(TestCaseWithNesting.class)).build();
    TestDescriptor engineDescriptor = discoverTests(request);
    assertEquals(5, engineDescriptor.getDescendants().size(), "# resolved test descriptors");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 48 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class OverloadedTestMethodTests method executeTestCaseWithOverloadedMethodsAndThenRerunOnlyOneOfTheMethodsSelectedByUniqueId.

@Test
void executeTestCaseWithOverloadedMethodsAndThenRerunOnlyOneOfTheMethodsSelectedByUniqueId() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(TestCase.class)).build();
    ExecutionEventRecorder eventRecorder1 = executeTests(request);
    // @formatter:off
    assertAll(() -> assertEquals(2, eventRecorder1.getTestStartedCount(), "# tests started"), () -> assertEquals(2, eventRecorder1.getTestSuccessfulCount(), "# tests succeeded"), () -> assertEquals(0, eventRecorder1.getTestFailedCount(), "# tests failed"));
    // @formatter:on
    Optional<ExecutionEvent> first = eventRecorder1.getSuccessfulTestFinishedEvents().stream().filter(event -> event.getTestDescriptor().getUniqueId().toString().contains(TestInfo.class.getName())).findFirst();
    assertTrue(first.isPresent());
    TestIdentifier testIdentifier = TestIdentifier.from(first.get().getTestDescriptor());
    String uniqueId = testIdentifier.getUniqueId();
    request = request().selectors(selectUniqueId(uniqueId)).build();
    ExecutionEventRecorder eventRecorder2 = executeTests(request);
    // @formatter:off
    assertAll(() -> assertEquals(1, eventRecorder2.getTestStartedCount(), "# tests started"), () -> assertEquals(1, eventRecorder2.getTestSuccessfulCount(), "# tests succeeded"), () -> assertEquals(0, eventRecorder2.getTestFailedCount(), "# tests failed"));
    // @formatter:on
    first = eventRecorder2.getSuccessfulTestFinishedEvents().stream().filter(event -> event.getTestDescriptor().getUniqueId().toString().contains(TestInfo.class.getName())).findFirst();
    assertTrue(first.isPresent());
}
Also used : LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) DiscoverySelectors.selectClass(org.junit.platform.engine.discovery.DiscoverySelectors.selectClass) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) TestIdentifier(org.junit.platform.launcher.TestIdentifier) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ExecutionEvent(org.junit.platform.engine.test.event.ExecutionEvent) Optional(java.util.Optional) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEvent(org.junit.platform.engine.test.event.ExecutionEvent) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) TestInfo(org.junit.jupiter.api.TestInfo) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 49 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class OverloadedTestMethodTests method executeTestCaseWithOverloadedMethodsWithSingleMethodThatAcceptsArgumentsSelectedByFullyQualifedMethodName.

@Test
void executeTestCaseWithOverloadedMethodsWithSingleMethodThatAcceptsArgumentsSelectedByFullyQualifedMethodName() {
    String fqmn = TestCase.class.getName() + "#test(" + TestInfo.class.getName() + ")";
    LauncherDiscoveryRequest request = request().selectors(selectMethod(fqmn)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    // @formatter:off
    assertAll(() -> assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started"), () -> assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded"), () -> assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed"));
    // @formatter:on
    Optional<ExecutionEvent> first = eventRecorder.getSuccessfulTestFinishedEvents().stream().filter(event -> event.getTestDescriptor().getUniqueId().toString().contains(TestInfo.class.getName())).findFirst();
    assertTrue(first.isPresent());
}
Also used : LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) DiscoverySelectors.selectClass(org.junit.platform.engine.discovery.DiscoverySelectors.selectClass) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) TestIdentifier(org.junit.platform.launcher.TestIdentifier) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ExecutionEvent(org.junit.platform.engine.test.event.ExecutionEvent) Optional(java.util.Optional) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEvent(org.junit.platform.engine.test.event.ExecutionEvent) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test)

Example 50 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class StandardTestClassTests method moreThanOneTestClassIsExecuted.

@Test
void moreThanOneTestClassIsExecuted() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(FirstOfTwoTestCases.class), selectClass(SecondOfTwoTestCases.class)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(6, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(5, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    assertEquals(3, eventRecorder.getContainerStartedCount(), "# containers started");
    assertEquals(3, eventRecorder.getContainerFinishedCount(), "# containers finished");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Aggregations

LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)158 Test (org.junit.jupiter.api.Test)141 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)74 TestDescriptor (org.junit.platform.engine.TestDescriptor)54 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)33 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)11 DiscoverySelectors.selectMethod (org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod)11 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)11 Method (java.lang.reflect.Method)9 Launcher (org.junit.platform.launcher.Launcher)9 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)5 Path (java.nio.file.Path)4 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)4 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)4 TestIdentifier (org.junit.platform.launcher.TestIdentifier)4 TestPlan (org.junit.platform.launcher.TestPlan)4