use of org.gradle.api.internal.tasks.testing.filter.TestSelectionMatcher in project gradle by gradle.
the class JUnitTestClassExecuter method runTestClass.
private void runTestClass(String testClassName) throws ClassNotFoundException {
final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader);
List<Filter> filters = new ArrayList<Filter>();
if (options.hasCategoryConfiguration()) {
verifyJUnitCategorySupport();
Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() {
public Class<?> transform(final String original) {
try {
return applicationClassLoader.loadClass(original);
} catch (ClassNotFoundException e) {
throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e);
}
}
};
filters.add(new CategoryFilter(CollectionUtils.collect(options.getIncludeCategories(), transformer), CollectionUtils.collect(options.getExcludeCategories(), transformer)));
}
Request request = Request.aClass(testClass);
Runner runner = request.getRunner();
if (!options.getIncludedTests().isEmpty()) {
TestSelectionMatcher matcher = new TestSelectionMatcher(options.getIncludedTests());
// matches the filter, run the entire suite instead of filtering away its contents.
if (!runner.getDescription().isSuite() || !matcher.matchesTest(testClassName, null)) {
filters.add(new MethodNameFilter(matcher));
}
}
if (runner instanceof Filterable) {
Filterable filterable = (Filterable) runner;
for (Filter filter : filters) {
try {
filterable.filter(filter);
} catch (NoTestsRemainException e) {
// Ignore
return;
}
}
} else if (allTestsFiltered(runner, filters)) {
return;
}
RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
runner.run(notifier);
}
Aggregations