Search in sources :

Example 1 with RunResult

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

use of org.apache.maven.surefire.suite.RunResult in project tycho by eclipse.

the class OsgiSurefireBooter method run.

public static int run(String[] args) throws Exception {
    Properties testProps = loadProperties(getTestProperties(args));
    boolean failIfNoTests = Boolean.parseBoolean(testProps.getProperty("failifnotests", "false"));
    boolean redirectTestOutputToFile = Boolean.parseBoolean(testProps.getProperty("redirectTestOutputToFile", "false"));
    String testPlugin = testProps.getProperty("testpluginname");
    File testClassesDir = new File(testProps.getProperty("testclassesdirectory"));
    File reportsDir = new File(testProps.getProperty("reportsdirectory"));
    String provider = testProps.getProperty("testprovider");
    String runOrder = testProps.getProperty("runOrder");
    int skipAfterFailureCount = Integer.parseInt(testProps.getProperty("skipAfterFailureCount", "0"));
    int rerunFailingTestsCount = Integer.parseInt(testProps.getProperty("rerunFailingTestsCount", "0"));
    Map<String, String> propertiesMap = new HashMap<String, String>();
    for (String key : testProps.stringPropertyNames()) {
        propertiesMap.put(key, testProps.getProperty(key));
    }
    PropertiesWrapper wrapper = new PropertiesWrapper(propertiesMap);
    List<String> suiteXmlFiles = wrapper.getStringList(BooterConstants.TEST_SUITE_XML_FILES);
    boolean forkRequested = true;
    boolean inForkedVM = true;
    boolean trimStacktrace = true;
    boolean useSystemClassloader = false;
    boolean useManifestOnlyJar = false;
    boolean useFile = true;
    boolean printSummary = true;
    boolean disableXmlReport = false;
    ClasspathConfiguration classPathConfig = new ClasspathConfiguration(false, false);
    StartupConfiguration startupConfiguration = new StartupConfiguration(provider, classPathConfig, new ClassLoaderConfiguration(useSystemClassloader, useManifestOnlyJar), forkRequested, inForkedVM);
    // TODO dir scanning with no includes done here (done in TestMojo already)
    // but without dirScannerParams we get an NPE accessing runOrder
    DirectoryScannerParameters dirScannerParams = new DirectoryScannerParameters(testClassesDir, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), failIfNoTests, runOrder);
    ReporterConfiguration reporterConfig = new ReporterConfiguration(reportsDir, trimStacktrace);
    TestRequest testRequest = new TestRequest(suiteXmlFiles, testClassesDir, TestListResolver.getEmptyTestListResolver());
    ProviderConfiguration providerConfiguration = new ProviderConfiguration(dirScannerParams, new RunOrderParameters(runOrder, null), failIfNoTests, reporterConfig, null, testRequest, extractProviderProperties(testProps), null, false, Collections.<CommandLineOption>emptyList(), skipAfterFailureCount, Shutdown.DEFAULT);
    StartupReportConfiguration startupReportConfig = new StartupReportConfiguration(useFile, printSummary, StartupReportConfiguration.PLAIN_REPORT_FORMAT, redirectTestOutputToFile, disableXmlReport, reportsDir, trimStacktrace, null, "TESTHASH", false, rerunFailingTestsCount);
    ReporterFactory reporterFactory = new DefaultReporterFactory(startupReportConfig);
    // API indicates we should use testClassLoader below but surefire also tries
    // to load surefire classes using this classloader
    RunResult result = ProviderFactory.invokeProvider(null, createCombinedClassLoader(testPlugin), reporterFactory, providerConfiguration, false, startupConfiguration, true);
    // counter-intuitive, but null indicates OK here
    return result.getFailsafeCode() == null ? 0 : result.getFailsafeCode();
}
Also used : ClasspathConfiguration(org.apache.maven.surefire.booter.ClasspathConfiguration) DefaultReporterFactory(org.apache.maven.plugin.surefire.report.DefaultReporterFactory) ReporterFactory(org.apache.maven.surefire.report.ReporterFactory) RunOrderParameters(org.apache.maven.surefire.testset.RunOrderParameters) HashMap(java.util.HashMap) StartupReportConfiguration(org.apache.maven.plugin.surefire.StartupReportConfiguration) DefaultReporterFactory(org.apache.maven.plugin.surefire.report.DefaultReporterFactory) StartupConfiguration(org.apache.maven.surefire.booter.StartupConfiguration) Properties(java.util.Properties) TestRequest(org.apache.maven.surefire.testset.TestRequest) ProviderConfiguration(org.apache.maven.surefire.booter.ProviderConfiguration) ClassLoaderConfiguration(org.apache.maven.surefire.booter.ClassLoaderConfiguration) DirectoryScannerParameters(org.apache.maven.surefire.testset.DirectoryScannerParameters) PropertiesWrapper(org.apache.maven.surefire.booter.PropertiesWrapper) File(java.io.File) ReporterConfiguration(org.apache.maven.surefire.report.ReporterConfiguration) RunResult(org.apache.maven.surefire.suite.RunResult)

Aggregations

ReporterFactory (org.apache.maven.surefire.report.ReporterFactory)2 RunResult (org.apache.maven.surefire.suite.RunResult)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 StartupReportConfiguration (org.apache.maven.plugin.surefire.StartupReportConfiguration)1 DefaultReporterFactory (org.apache.maven.plugin.surefire.report.DefaultReporterFactory)1 ClassLoaderConfiguration (org.apache.maven.surefire.booter.ClassLoaderConfiguration)1 ClasspathConfiguration (org.apache.maven.surefire.booter.ClasspathConfiguration)1 PropertiesWrapper (org.apache.maven.surefire.booter.PropertiesWrapper)1 ProviderConfiguration (org.apache.maven.surefire.booter.ProviderConfiguration)1 StartupConfiguration (org.apache.maven.surefire.booter.StartupConfiguration)1 ReporterConfiguration (org.apache.maven.surefire.report.ReporterConfiguration)1 RunListener (org.apache.maven.surefire.report.RunListener)1 DirectoryScannerParameters (org.apache.maven.surefire.testset.DirectoryScannerParameters)1 RunOrderParameters (org.apache.maven.surefire.testset.RunOrderParameters)1 TestRequest (org.apache.maven.surefire.testset.TestRequest)1 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)1