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);
}
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
}
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;
}
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());
}
Aggregations