Search in sources :

Example 1 with Launcher

use of org.junit.platform.launcher.Launcher in project spring-framework by spring-projects.

the class FailingBeforeAndAfterMethodsSpringExtensionTestCase method runTestAndAssertCounters.

private void runTestAndAssertCounters(Class<?> testClass) {
    Launcher launcher = LauncherFactory.create();
    ExceptionTrackingListener listener = new ExceptionTrackingListener();
    launcher.registerTestExecutionListeners(listener);
    launcher.execute(request().selectors(selectClass(testClass)).build());
    TestExecutionSummary summary = listener.getSummary();
    String name = testClass.getSimpleName();
    int expectedStartedCount = getExpectedStartedCount(testClass);
    int expectedSucceededCount = getExpectedSucceededCount(testClass);
    int expectedFailedCount = getExpectedFailedCount(testClass);
    // @formatter:off
    assertAll(() -> assertEquals(1, summary.getTestsFoundCount(), () -> name + ": tests found"), () -> assertEquals(0, summary.getTestsSkippedCount(), () -> name + ": tests skipped"), () -> assertEquals(0, summary.getTestsAbortedCount(), () -> name + ": tests aborted"), () -> assertEquals(expectedStartedCount, summary.getTestsStartedCount(), () -> name + ": tests started"), () -> assertEquals(expectedSucceededCount, summary.getTestsSucceededCount(), () -> name + ": tests succeeded"), () -> assertEquals(expectedFailedCount, summary.getTestsFailedCount(), () -> name + ": tests failed"));
    // something else like an error in the @Configuration class, etc.
    if (expectedFailedCount > 0) {
        assertEquals(1, listener.exceptions.size(), "exceptions expected");
        Throwable exception = listener.exceptions.get(0);
        if (!(exception instanceof AssertionFailedError)) {
            throw new AssertionFailedError(exception.getClass().getName() + " is not an instance of " + AssertionFailedError.class.getName(), exception);
        }
    }
}
Also used : TestExecutionSummary(org.junit.platform.launcher.listeners.TestExecutionSummary) Launcher(org.junit.platform.launcher.Launcher) AssertionFailedError(org.opentest4j.AssertionFailedError)

Example 2 with Launcher

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

the class ConsoleTestExecutor method executeTests.

private TestExecutionSummary executeTests(PrintWriter out) {
    Launcher launcher = launcherSupplier.get();
    SummaryGeneratingListener summaryListener = registerListeners(out, launcher);
    LauncherDiscoveryRequest discoveryRequest = new DiscoveryRequestCreator().toDiscoveryRequest(options);
    launcher.execute(discoveryRequest);
    TestExecutionSummary summary = summaryListener.getSummary();
    if (summary.getTotalFailureCount() > 0 || options.getDetails() != Details.NONE) {
        printSummary(summary, out);
    }
    return summary;
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) TestExecutionSummary(org.junit.platform.launcher.listeners.TestExecutionSummary) Launcher(org.junit.platform.launcher.Launcher)

Example 3 with Launcher

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

the class JUnitPlatformRunnerTests method instantiateRunnerAndCaptureGeneratedRequest.

private LauncherDiscoveryRequest instantiateRunnerAndCaptureGeneratedRequest(Class<?> testClass) throws InitializationError {
    Launcher launcher = mock(Launcher.class);
    ArgumentCaptor<LauncherDiscoveryRequest> captor = ArgumentCaptor.forClass(LauncherDiscoveryRequest.class);
    when(launcher.discover(captor.capture())).thenReturn(TestPlan.from(emptySet()));
    new JUnitPlatform(testClass, launcher);
    return captor.getValue();
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) Launcher(org.junit.platform.launcher.Launcher) LauncherFactoryForTestingPurposesOnly.createLauncher(org.junit.platform.launcher.core.LauncherFactoryForTestingPurposesOnly.createLauncher)

Example 4 with Launcher

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

the class JUnitPlatformProviderTests method allGivenTestsToRunAreInvoked.

@Test
void allGivenTestsToRunAreInvoked() throws Exception {
    Launcher launcher = LauncherFactory.create();
    JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher);
    TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
    launcher.registerTestExecutionListeners(executionListener);
    TestsToRun testsToRun = newTestsToRun(TestClass1.class, TestClass2.class);
    invokeProvider(provider, testsToRun);
    assertThat(executionListener.summaries).hasSize(1);
    TestExecutionSummary summary = executionListener.summaries.get(0);
    assertEquals(TestClass1.TESTS_FOUND + TestClass2.TESTS_FOUND, summary.getTestsFoundCount());
    assertEquals(TestClass1.TESTS_STARTED + TestClass2.TESTS_STARTED, summary.getTestsStartedCount());
    assertEquals(TestClass1.TESTS_SKIPPED + TestClass2.TESTS_SKIPPED, summary.getTestsSkippedCount());
    assertEquals(TestClass1.TESTS_SUCCEEDED + TestClass2.TESTS_SUCCEEDED, summary.getTestsSucceededCount());
    assertEquals(TestClass1.TESTS_ABORTED + TestClass2.TESTS_ABORTED, summary.getTestsAbortedCount());
    assertEquals(TestClass1.TESTS_FAILED + TestClass2.TESTS_FAILED, summary.getTestsFailedCount());
}
Also used : TestExecutionSummary(org.junit.platform.launcher.listeners.TestExecutionSummary) Launcher(org.junit.platform.launcher.Launcher) TestsToRun(org.apache.maven.surefire.util.TestsToRun) Test(org.junit.jupiter.api.Test)

Example 5 with Launcher

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

the class JUnitPlatformProviderTests method outputIsCaptured.

@Test
void outputIsCaptured() throws Exception {
    Launcher launcher = LauncherFactory.create();
    RunListener runListener = runListenerMock();
    JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(runListener), launcher);
    invokeProvider(provider, VerboseTestClass.class);
    ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
    // @formatter:off
    verify((ConsoleOutputReceiver) runListener).writeTestOutput(captor.capture(), eq(0), gt(6), eq(true));
    verify((ConsoleOutputReceiver) runListener).writeTestOutput(captor.capture(), eq(0), gt(6), eq(false));
    assertThat(captor.getAllValues()).extracting(bytes -> new String(bytes, 0, 6)).containsExactly("stdout", "stderr");
// @formatter:on
}
Also used : Arrays(java.util.Arrays) TestPlan(org.junit.platform.launcher.TestPlan) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScanResult(org.apache.maven.surefire.util.ScanResult) Disabled(org.junit.jupiter.api.Disabled) TestsToRun(org.apache.maven.surefire.util.TestsToRun) TestExecutionSummary(org.junit.platform.launcher.listeners.TestExecutionSummary) Map(java.util.Map) RunListener(org.apache.maven.surefire.report.RunListener) LauncherFactory(org.junit.platform.launcher.core.LauncherFactory) TestListResolver(org.apache.maven.surefire.testset.TestListResolver) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) Failure(org.junit.platform.launcher.listeners.TestExecutionSummary.Failure) ConsoleOutputReceiver(org.apache.maven.surefire.report.ConsoleOutputReceiver) RunOrderCalculator(org.apache.maven.surefire.util.RunOrderCalculator) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.jupiter.api.Test) TestIdentifier(org.junit.platform.launcher.TestIdentifier) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) List(java.util.List) TestRequest(org.apache.maven.surefire.testset.TestRequest) Mockito.inOrder(org.mockito.Mockito.inOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) Mockito.withSettings(org.mockito.Mockito.withSettings) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ProviderParameters(org.apache.maven.surefire.providerapi.ProviderParameters) ReportEntry(org.apache.maven.surefire.report.ReportEntry) Launcher(org.junit.platform.launcher.Launcher) HashMap(java.util.HashMap) TestSetFailedException(org.apache.maven.surefire.testset.TestSetFailedException) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LinkedHashSet(java.util.LinkedHashSet) PrintStream(java.io.PrintStream) Collections.emptyMap(java.util.Collections.emptyMap) InOrder(org.mockito.InOrder) ReporterFactory(org.apache.maven.surefire.report.ReporterFactory) AdditionalMatchers.gt(org.mockito.AdditionalMatchers.gt) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) Launcher(org.junit.platform.launcher.Launcher) ConsoleOutputReceiver(org.apache.maven.surefire.report.ConsoleOutputReceiver) RunListener(org.apache.maven.surefire.report.RunListener) Test(org.junit.jupiter.api.Test)

Aggregations

Launcher (org.junit.platform.launcher.Launcher)25 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)15 TestExecutionSummary (org.junit.platform.launcher.listeners.TestExecutionSummary)8 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)7 TestPlan (org.junit.platform.launcher.TestPlan)6 Test (org.junit.jupiter.api.Test)5 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)5 ProviderParameters (org.apache.maven.surefire.providerapi.ProviderParameters)3 TestIdentifier (org.junit.platform.launcher.TestIdentifier)3 PrintStream (java.io.PrintStream)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 RunListener (org.apache.maven.surefire.report.RunListener)2 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)2 TestListResolver (org.apache.maven.surefire.testset.TestListResolver)2 TestsToRun (org.apache.maven.surefire.util.TestsToRun)2 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1