Search in sources :

Example 1 with RunListener

use of org.apache.maven.surefire.report.RunListener in project junit5 by junit-team.

the class JUnitPlatformProviderTests method usesClassNamesForXmlReport.

@Test
void usesClassNamesForXmlReport() throws TestSetFailedException, InvocationTargetException {
    String[] classNames = { "org.junit.platform.surefire.provider.JUnitPlatformProviderTests$Sub1Tests", "org.junit.platform.surefire.provider.JUnitPlatformProviderTests$Sub2Tests" };
    ProviderParameters providerParameters = providerParametersMock(Sub1Tests.class, Sub2Tests.class);
    JUnitPlatformProvider jUnitPlatformProvider = new JUnitPlatformProvider(providerParameters);
    TestsToRun testsToRun = newTestsToRun(Sub1Tests.class, Sub2Tests.class);
    invokeProvider(jUnitPlatformProvider, testsToRun);
    RunListener reporter = providerParameters.getReporterFactory().createReporter();
    ArgumentCaptor<ReportEntry> reportEntryArgumentCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    verify(reporter, times(2)).testSucceeded(reportEntryArgumentCaptor.capture());
    List<ReportEntry> allValues = reportEntryArgumentCaptor.getAllValues();
    assertThat(allValues).extracting(ReportEntry::getSourceName).containsExactly(classNames);
}
Also used : ProviderParameters(org.apache.maven.surefire.providerapi.ProviderParameters) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) ReportEntry(org.apache.maven.surefire.report.ReportEntry) TestsToRun(org.apache.maven.surefire.util.TestsToRun) RunListener(org.apache.maven.surefire.report.RunListener) Test(org.junit.jupiter.api.Test)

Example 2 with RunListener

use of org.apache.maven.surefire.report.RunListener 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)

Example 3 with RunListener

use of org.apache.maven.surefire.report.RunListener in project junit5 by junit-team.

the class JUnitPlatformProvider method invokeAllTests.

private RunResult invokeAllTests(TestsToRun testsToRun) {
    RunResult runResult;
    ReporterFactory reporterFactory = parameters.getReporterFactory();
    try {
        RunListener runListener = reporterFactory.createReporter();
        ConsoleOutputCapture.startCapture((ConsoleOutputReceiver) runListener);
        LauncherDiscoveryRequest discoveryRequest = buildLauncherDiscoveryRequest(testsToRun);
        launcher.execute(discoveryRequest, new RunListenerAdapter(runListener));
    } finally {
        runResult = reporterFactory.close();
    }
    return runResult;
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ReporterFactory(org.apache.maven.surefire.report.ReporterFactory) RunResult(org.apache.maven.surefire.suite.RunResult) RunListener(org.apache.maven.surefire.report.RunListener)

Example 4 with RunListener

use of org.apache.maven.surefire.report.RunListener in project junit5 by junit-team.

the class JUnitPlatformProviderTests method allDiscoveredTestsAreInvokedForNullArgument.

@Test
void allDiscoveredTestsAreInvokedForNullArgument() throws Exception {
    RunListener runListener = runListenerMock();
    ProviderParameters providerParameters = providerParametersMock(runListener, TestClass1.class, TestClass2.class);
    Launcher launcher = LauncherFactory.create();
    JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters, launcher);
    TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
    launcher.registerTestExecutionListeners(executionListener);
    invokeProvider(provider, null);
    InOrder inOrder = inOrder(runListener);
    inOrder.verify(runListener).testSetStarting(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), TestClass1.class.getName()));
    inOrder.verify(runListener).testSetCompleted(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), TestClass1.class.getName()));
    inOrder.verify(runListener).testSetStarting(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), TestClass2.class.getName()));
    inOrder.verify(runListener).testSetCompleted(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), TestClass2.class.getName()));
    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 : ProviderParameters(org.apache.maven.surefire.providerapi.ProviderParameters) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) InOrder(org.mockito.InOrder) TestExecutionSummary(org.junit.platform.launcher.listeners.TestExecutionSummary) Launcher(org.junit.platform.launcher.Launcher) RunListener(org.apache.maven.surefire.report.RunListener) Test(org.junit.jupiter.api.Test)

Aggregations

RunListener (org.apache.maven.surefire.report.RunListener)4 ProviderParameters (org.apache.maven.surefire.providerapi.ProviderParameters)3 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)3 Test (org.junit.jupiter.api.Test)3 ReportEntry (org.apache.maven.surefire.report.ReportEntry)2 ReporterFactory (org.apache.maven.surefire.report.ReporterFactory)2 TestsToRun (org.apache.maven.surefire.util.TestsToRun)2 Launcher (org.junit.platform.launcher.Launcher)2 TestExecutionSummary (org.junit.platform.launcher.listeners.TestExecutionSummary)2 PrintStream (java.io.PrintStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1