Search in sources :

Example 1 with TestsToRun

use of org.apache.maven.surefire.util.TestsToRun 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 2 with TestsToRun

use of org.apache.maven.surefire.util.TestsToRun in project junit5 by junit-team.

the class JUnitPlatformProvider method scanClasspath.

private TestsToRun scanClasspath() {
    TestPlanScannerFilter filter = new TestPlanScannerFilter(launcher, filters);
    ScanResult scanResult = parameters.getScanResult();
    TestsToRun scannedClasses = scanResult.applyFilter(filter, parameters.getTestClassLoader());
    return parameters.getRunOrderCalculator().orderTestClasses(scannedClasses);
}
Also used : ScanResult(org.apache.maven.surefire.util.ScanResult) TestsToRun(org.apache.maven.surefire.util.TestsToRun)

Example 3 with TestsToRun

use of org.apache.maven.surefire.util.TestsToRun 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 4 with TestsToRun

use of org.apache.maven.surefire.util.TestsToRun in project junit5 by junit-team.

the class JUnitPlatformProviderTests method providerParametersMock.

private static ProviderParameters providerParametersMock(RunListener runListener, TestListResolver testListResolver, Class<?>... testClasses) {
    TestsToRun testsToRun = newTestsToRun(testClasses);
    ScanResult scanResult = mock(ScanResult.class);
    when(scanResult.applyFilter(any(), any())).thenReturn(testsToRun);
    RunOrderCalculator runOrderCalculator = mock(RunOrderCalculator.class);
    when(runOrderCalculator.orderTestClasses(any())).thenReturn(testsToRun);
    ReporterFactory reporterFactory = mock(ReporterFactory.class);
    when(reporterFactory.createReporter()).thenReturn(runListener);
    TestRequest testRequest = mock(TestRequest.class);
    when(testRequest.getTestListResolver()).thenReturn(testListResolver);
    ProviderParameters providerParameters = mock(ProviderParameters.class);
    when(providerParameters.getScanResult()).thenReturn(scanResult);
    when(providerParameters.getRunOrderCalculator()).thenReturn(runOrderCalculator);
    when(providerParameters.getReporterFactory()).thenReturn(reporterFactory);
    when(providerParameters.getTestRequest()).thenReturn(testRequest);
    return providerParameters;
}
Also used : RunOrderCalculator(org.apache.maven.surefire.util.RunOrderCalculator) ProviderParameters(org.apache.maven.surefire.providerapi.ProviderParameters) ScanResult(org.apache.maven.surefire.util.ScanResult) ReporterFactory(org.apache.maven.surefire.report.ReporterFactory) TestsToRun(org.apache.maven.surefire.util.TestsToRun) TestRequest(org.apache.maven.surefire.testset.TestRequest)

Aggregations

TestsToRun (org.apache.maven.surefire.util.TestsToRun)4 ProviderParameters (org.apache.maven.surefire.providerapi.ProviderParameters)2 ScanResult (org.apache.maven.surefire.util.ScanResult)2 Test (org.junit.jupiter.api.Test)2 ReportEntry (org.apache.maven.surefire.report.ReportEntry)1 ReporterFactory (org.apache.maven.surefire.report.ReporterFactory)1 RunListener (org.apache.maven.surefire.report.RunListener)1 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)1 TestRequest (org.apache.maven.surefire.testset.TestRequest)1 RunOrderCalculator (org.apache.maven.surefire.util.RunOrderCalculator)1 Launcher (org.junit.platform.launcher.Launcher)1 TestExecutionSummary (org.junit.platform.launcher.listeners.TestExecutionSummary)1