Search in sources :

Example 1 with TestRequest

use of org.apache.maven.surefire.api.testset.TestRequest in project maven-surefire by apache.

the class BooterDeserializerProviderConfigurationTest method testTestRequest.

public void testTestRequest() throws IOException {
    ProviderConfiguration reloaded = getReloadedProviderConfiguration();
    TestRequest testSuiteDefinition = reloaded.getTestSuiteDefinition();
    List<?> suiteXmlFiles = testSuiteDefinition.getSuiteXmlFiles();
    File[] expected = getSuiteXmlFiles();
    Assert.assertEquals(expected[0], suiteXmlFiles.get(0));
    Assert.assertEquals(expected[1], suiteXmlFiles.get(1));
    Assert.assertEquals(getTestSourceDirectory(), testSuiteDefinition.getTestSourceDirectory());
    TestListResolver resolver = testSuiteDefinition.getTestListResolver();
    Assert.assertNotNull(resolver);
    Assert.assertFalse(resolver.isEmpty());
    Assert.assertEquals(USER_REQUESTED_TEST + "#" + USER_REQUESTED_TEST_METHOD, resolver.getPluginParameterTest());
    Assert.assertFalse(resolver.getIncludedPatterns().isEmpty());
    Assert.assertTrue(resolver.getExcludedPatterns().isEmpty());
    Assert.assertEquals(1, resolver.getIncludedPatterns().size());
    ResolvedTest filter = resolver.getIncludedPatterns().iterator().next();
    Assert.assertNotNull(filter);
    Assert.assertEquals("**/" + USER_REQUESTED_TEST, filter.getTestClassPattern());
    Assert.assertEquals(USER_REQUESTED_TEST_METHOD, filter.getTestMethodPattern());
    Assert.assertEquals(RERUN_FAILING_TEST_COUNT, testSuiteDefinition.getRerunFailingTestsCount());
    assertEquals(cli, reloaded.getMainCliOptions());
}
Also used : ResolvedTest(org.apache.maven.surefire.api.testset.ResolvedTest) TestListResolver(org.apache.maven.surefire.api.testset.TestListResolver) File(java.io.File) ProviderConfiguration(org.apache.maven.surefire.booter.ProviderConfiguration) TestRequest(org.apache.maven.surefire.api.testset.TestRequest)

Example 2 with TestRequest

use of org.apache.maven.surefire.api.testset.TestRequest in project maven-surefire by apache.

the class BooterDeserializer method deserialize.

public ProviderConfiguration deserialize() {
    final File reportsDirectory = new File(properties.getProperty(REPORTSDIRECTORY));
    final String testNgVersion = properties.getProperty(TESTARTIFACT_VERSION);
    final String testArtifactClassifier = properties.getProperty(TESTARTIFACT_CLASSIFIER);
    final TypeEncodedValue typeEncodedTestForFork = properties.getTypeEncodedValue(FORKTESTSET);
    final boolean preferTestsFromInStream = properties.getBooleanProperty(FORKTESTSET_PREFER_TESTS_FROM_IN_STREAM);
    final String requestedTest = properties.getProperty(REQUESTEDTEST);
    final File sourceDirectory = properties.getFileProperty(SOURCE_DIRECTORY);
    final List<String> excludes = properties.getStringList(EXCLUDES_PROPERTY_PREFIX);
    final List<String> includes = properties.getStringList(INCLUDES_PROPERTY_PREFIX);
    final List<String> specificTests = properties.getStringList(SPECIFIC_TEST_PROPERTY_PREFIX);
    final List<String> testSuiteXmlFiles = properties.getStringList(TEST_SUITE_XML_FILES);
    final File testClassesDirectory = properties.getFileProperty(TEST_CLASSES_DIRECTORY);
    final String runOrder = properties.getProperty(RUN_ORDER);
    final Long runOrderRandomSeed = properties.getLongProperty(RUN_ORDER_RANDOM_SEED);
    final String runStatisticsFile = properties.getProperty(RUN_STATISTICS_FILE);
    final int rerunFailingTestsCount = properties.getIntProperty(RERUN_FAILING_TESTS_COUNT);
    DirectoryScannerParameters dirScannerParams = new DirectoryScannerParameters(testClassesDirectory, includes, excludes, specificTests, runOrder);
    RunOrderParameters runOrderParameters = new RunOrderParameters(runOrder, runStatisticsFile == null ? null : new File(runStatisticsFile), runOrderRandomSeed);
    TestArtifactInfo testNg = new TestArtifactInfo(testNgVersion, testArtifactClassifier);
    TestRequest testSuiteDefinition = new TestRequest(testSuiteXmlFiles, sourceDirectory, new TestListResolver(requestedTest), rerunFailingTestsCount);
    ReporterConfiguration reporterConfiguration = new ReporterConfiguration(reportsDirectory, properties.getBooleanProperty(ISTRIMSTACKTRACE));
    Collection<String> cli = properties.getStringList(MAIN_CLI_OPTIONS);
    int failFastCount = properties.getIntProperty(FAIL_FAST_COUNT);
    Shutdown shutdown = Shutdown.valueOf(properties.getProperty(SHUTDOWN));
    String systemExitTimeoutAsString = properties.getProperty(SYSTEM_EXIT_TIMEOUT);
    Integer systemExitTimeout = systemExitTimeoutAsString == null ? null : Integer.valueOf(systemExitTimeoutAsString);
    return new ProviderConfiguration(dirScannerParams, runOrderParameters, reporterConfiguration, testNg, testSuiteDefinition, properties.getProperties(), typeEncodedTestForFork, preferTestsFromInStream, fromStrings(cli), failFastCount, shutdown, systemExitTimeout);
}
Also used : RunOrderParameters(org.apache.maven.surefire.api.testset.RunOrderParameters) TestListResolver(org.apache.maven.surefire.api.testset.TestListResolver) TestRequest(org.apache.maven.surefire.api.testset.TestRequest) TestArtifactInfo(org.apache.maven.surefire.api.testset.TestArtifactInfo) Shutdown(org.apache.maven.surefire.api.booter.Shutdown) DirectoryScannerParameters(org.apache.maven.surefire.api.testset.DirectoryScannerParameters) File(java.io.File) ReporterConfiguration(org.apache.maven.surefire.api.report.ReporterConfiguration)

Example 3 with TestRequest

use of org.apache.maven.surefire.api.testset.TestRequest in project maven-surefire by apache.

the class JUnitPlatformProviderTest method providerParametersMock.

private static ProviderParameters providerParametersMock(TestReportListener<TestOutputReportEntry> 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.createTestReportListener()).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.api.util.RunOrderCalculator) ProviderParameters(org.apache.maven.surefire.api.provider.ProviderParameters) ScanResult(org.apache.maven.surefire.api.util.ScanResult) ReporterFactory(org.apache.maven.surefire.api.report.ReporterFactory) TestsToRun(org.apache.maven.surefire.api.util.TestsToRun) TestRequest(org.apache.maven.surefire.api.testset.TestRequest)

Example 4 with TestRequest

use of org.apache.maven.surefire.api.testset.TestRequest in project maven-surefire by apache.

the class JUnit4ProviderTest method getJUnit4Provider.

private JUnit4Provider getJUnit4Provider() {
    BaseProviderFactory providerParameters = new BaseProviderFactory(true);
    providerParameters.setProviderProperties(new HashMap<String, String>());
    providerParameters.setClassLoaders(getClass().getClassLoader());
    providerParameters.setTestRequest(new TestRequest(null, null, null));
    providerParameters.setRunOrderParameters(new RunOrderParameters("hourly", new File("")));
    return new JUnit4Provider(providerParameters);
}
Also used : RunOrderParameters(org.apache.maven.surefire.api.testset.RunOrderParameters) BaseProviderFactory(org.apache.maven.surefire.api.booter.BaseProviderFactory) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) File(java.io.File) TestRequest(org.apache.maven.surefire.api.testset.TestRequest)

Example 5 with TestRequest

use of org.apache.maven.surefire.api.testset.TestRequest in project maven-surefire by apache.

the class AbstractSurefireMojo method createProviderConfiguration.

private ProviderConfiguration createProviderConfiguration(RunOrderParameters runOrderParameters) throws MojoExecutionException, MojoFailureException {
    final ReporterConfiguration reporterConfiguration = new ReporterConfiguration(getReportsDirectory(), isTrimStackTrace());
    final Artifact testNgArtifact = getTestNgArtifact();
    final boolean isTestNg = testNgArtifact != null;
    final TestArtifactInfo testNg = isTestNg ? new TestArtifactInfo(testNgArtifact.getVersion(), testNgArtifact.getClassifier()) : null;
    final TestRequest testSuiteDefinition = new TestRequest(suiteXmlFiles(), getTestSourceDirectory(), getSpecificTests(), getRerunFailingTestsCount());
    final boolean actualFailIfNoTests;
    DirectoryScannerParameters directoryScannerParameters = null;
    if (hasSuiteXmlFiles() && !isSpecificTestSpecified()) {
        actualFailIfNoTests = getFailIfNoTests();
        if (!isTestNg) {
            throw new MojoExecutionException("suiteXmlFiles is configured, but there is no TestNG dependency");
        }
    } else {
        // @todo remove these three params and use DirectoryScannerParameters to pass into DirectoryScanner only
        // @todo or remove it in next major version :: 3.0
        // @todo remove deprecated methods in ProviderParameters => included|excluded|specificTests not needed here
        // Collections.emptyList(); behaves same
        List<String> actualIncludes = getIncludeList();
        // Collections.emptyList(); behaves same
        List<String> actualExcludes = getExcludeList();
        // Collections.emptyList(); behaves same
        List<String> specificTests = Collections.emptyList();
        directoryScannerParameters = new DirectoryScannerParameters(getTestClassesDirectory(), actualIncludes, actualExcludes, specificTests, getRunOrder());
    }
    Map<String, String> providerProperties = toStringProperties(getProperties());
    return new ProviderConfiguration(directoryScannerParameters, runOrderParameters, reporterConfiguration, // Not really used in provider. Limited to de/serializer.
    testNg, testSuiteDefinition, providerProperties, null, false, cli, getSkipAfterFailureCount(), Shutdown.parameterOf(getShutdown()), getForkedProcessExitTimeoutInSeconds());
}
Also used : TestArtifactInfo(org.apache.maven.surefire.api.testset.TestArtifactInfo) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DirectoryScannerParameters(org.apache.maven.surefire.api.testset.DirectoryScannerParameters) ReporterConfiguration(org.apache.maven.surefire.api.report.ReporterConfiguration) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) TestRequest(org.apache.maven.surefire.api.testset.TestRequest) ProviderConfiguration(org.apache.maven.surefire.booter.ProviderConfiguration)

Aggregations

TestRequest (org.apache.maven.surefire.api.testset.TestRequest)11 File (java.io.File)8 ReporterConfiguration (org.apache.maven.surefire.api.report.ReporterConfiguration)6 RunOrderParameters (org.apache.maven.surefire.api.testset.RunOrderParameters)6 TestListResolver (org.apache.maven.surefire.api.testset.TestListResolver)6 DirectoryScannerParameters (org.apache.maven.surefire.api.testset.DirectoryScannerParameters)5 TestArtifactInfo (org.apache.maven.surefire.api.testset.TestArtifactInfo)5 ProviderConfiguration (org.apache.maven.surefire.booter.ProviderConfiguration)5 ReporterFactory (org.apache.maven.surefire.api.report.ReporterFactory)2 ClassLoaderConfiguration (org.apache.maven.surefire.booter.ClassLoaderConfiguration)2 HashMap (java.util.HashMap)1 Artifact (org.apache.maven.artifact.Artifact)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 StartupReportConfiguration (org.apache.maven.plugin.surefire.StartupReportConfiguration)1 SurefireProperties (org.apache.maven.plugin.surefire.SurefireProperties)1 SurefireConsoleOutputReporter (org.apache.maven.plugin.surefire.extensions.SurefireConsoleOutputReporter)1 SurefireStatelessReporter (org.apache.maven.plugin.surefire.extensions.SurefireStatelessReporter)1 SurefireStatelessTestsetInfoReporter (org.apache.maven.plugin.surefire.extensions.SurefireStatelessTestsetInfoReporter)1 PrintStreamLogger (org.apache.maven.plugin.surefire.log.api.PrintStreamLogger)1