Search in sources :

Example 1 with TestListResolver

use of org.apache.maven.surefire.testset.TestListResolver in project tycho by eclipse.

the class TestMojo method scanForTests.

protected ScanResult scanForTests() {
    List<String> defaultIncludes = Arrays.asList("**/Test*.class", "**/*Test.class", "**/*TestCase.class");
    List<String> defaultExcludes = Arrays.asList("**/*$*");
    List<String> includeList;
    List<String> excludeList;
    if (test != null) {
        String test = this.test;
        test = test.replace('.', '/');
        test = test.endsWith(".class") ? test : test + ".class";
        test = test.startsWith("**/") ? test : "**/" + test;
        includeList = Collections.singletonList(test);
    } else if (testClass != null) {
        includeList = Collections.singletonList(testClass.replace('.', '/') + ".class");
    } else if (includes != null) {
        includeList = includes;
        includeList.removeAll(Collections.singleton(null));
    } else {
        includeList = defaultIncludes;
    }
    if (excludes != null) {
        excludeList = excludes;
        excludeList.removeAll(Collections.singleton(null));
    } else {
        excludeList = defaultExcludes;
    }
    // TODO bug 495353 we should we rather let TestListResolver do the work here
    // by passing in the unparsed String or Strings instead of already parsed include/exclude list
    // (this would add support for running single test methods, negation etc.)
    TestListResolver resolver = new TestListResolver(includeList, excludeList);
    DirectoryScanner scanner = new DirectoryScanner(testClassesDirectory, resolver);
    DefaultScanResult scanResult = scanner.scan();
    return scanResult;
}
Also used : DefaultScanResult(org.apache.maven.surefire.util.DefaultScanResult) DirectoryScanner(org.apache.maven.plugin.surefire.util.DirectoryScanner) TestListResolver(org.apache.maven.surefire.testset.TestListResolver)

Example 2 with TestListResolver

use of org.apache.maven.surefire.testset.TestListResolver in project junit5 by junit-team.

the class JUnitPlatformProvider method getFilters.

private Filter<?>[] getFilters() {
    List<Filter<?>> filters = new ArrayList<>();
    Optional<List<String>> includes = getGroupsOrTags(getPropertiesList(INCLUDE_GROUPS), getPropertiesList(INCLUDE_TAGS));
    includes.map(TagFilter::includeTags).ifPresent(filters::add);
    Optional<List<String>> excludes = getGroupsOrTags(getPropertiesList(EXCLUDE_GROUPS), getPropertiesList(EXCLUDE_TAGS));
    excludes.map(TagFilter::excludeTags).ifPresent(filters::add);
    TestListResolver testListResolver = parameters.getTestRequest().getTestListResolver();
    if (!testListResolver.isEmpty()) {
        filters.add(new TestMethodFilter(testListResolver));
    }
    return filters.toArray(new Filter<?>[filters.size()]);
}
Also used : Filter(org.junit.platform.engine.Filter) TagFilter(org.junit.platform.launcher.TagFilter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TestListResolver(org.apache.maven.surefire.testset.TestListResolver)

Example 3 with TestListResolver

use of org.apache.maven.surefire.testset.TestListResolver in project junit5 by junit-team.

the class JUnitPlatformProviderTests method testExecutionOfMatchingTestMethods.

void testExecutionOfMatchingTestMethods(Class<?> testClass, String pattern, String... expectedTestNames) throws Exception {
    TestListResolver testListResolver = new TestListResolver(pattern);
    ProviderParameters providerParameters = providerParametersMock(testListResolver, testClass);
    Launcher launcher = LauncherFactory.create();
    JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters, launcher);
    TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
    launcher.registerTestExecutionListeners(executionListener);
    invokeProvider(provider, null);
    assertEquals(1, executionListener.summaries.size());
    TestExecutionSummary summary = executionListener.summaries.get(0);
    int expectedCount = expectedTestNames.length;
    assertEquals(expectedCount, summary.getTestsFoundCount());
    assertEquals(expectedCount, summary.getTestsFailedCount());
    assertEquals(expectedCount, summary.getFailures().size());
    assertThat(failedTestDisplayNames(summary)).contains(expectedTestNames);
}
Also used : ProviderParameters(org.apache.maven.surefire.providerapi.ProviderParameters) TestExecutionSummary(org.junit.platform.launcher.listeners.TestExecutionSummary) Launcher(org.junit.platform.launcher.Launcher) TestListResolver(org.apache.maven.surefire.testset.TestListResolver)

Aggregations

TestListResolver (org.apache.maven.surefire.testset.TestListResolver)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DirectoryScanner (org.apache.maven.plugin.surefire.util.DirectoryScanner)1 ProviderParameters (org.apache.maven.surefire.providerapi.ProviderParameters)1 DefaultScanResult (org.apache.maven.surefire.util.DefaultScanResult)1 Filter (org.junit.platform.engine.Filter)1 Launcher (org.junit.platform.launcher.Launcher)1 TagFilter (org.junit.platform.launcher.TagFilter)1 TestExecutionSummary (org.junit.platform.launcher.listeners.TestExecutionSummary)1