use of org.junit.runner.Runner in project gradle by gradle.
the class JUnitTestClassExecutor method runTestClass.
private void runTestClass(String testClassName) throws ClassNotFoundException {
final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader);
if (isNestedClassInsideEnclosedRunner(testClass)) {
return;
}
List<Filter> filters = new ArrayList<Filter>();
if (options.hasCategoryConfiguration()) {
verifyJUnitCategorySupport();
filters.add(new CategoryFilter(options.getIncludeCategories(), options.getExcludeCategories(), applicationClassLoader));
}
Request request = Request.aClass(testClass);
Runner runner = request.getRunner();
if (!options.getIncludedTests().isEmpty() || !options.getIncludedTestsCommandLine().isEmpty() || !options.getExcludedTests().isEmpty()) {
TestSelectionMatcher matcher = new TestSelectionMatcher(options.getIncludedTests(), options.getExcludedTests(), options.getIncludedTestsCommandLine());
// 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);
}
use of org.junit.runner.Runner in project bazel by bazelbuild.
the class Filters method apply.
/**
* Returns a Request that only contains those tests that should run when
* a filter is applied, filtering out all empty suites.<p>
*
* Note that if the request passed into this method caches its runner,
* that runner will be modified to use the given filter. To be safe,
* do not use the passed-in request after calling this method.
*
* @param request Request to filter
* @param filter Filter to apply
* @return request
* @throws NoTestsRemainException if the applying the filter removes all tests
*/
public static Request apply(Request request, Filter filter) throws NoTestsRemainException {
filter = new SuiteTrimmingFilter(filter);
Runner runner = request.getRunner();
filter.apply(runner);
return Request.runner(runner);
}
use of org.junit.runner.Runner in project bazel by bazelbuild.
the class MemoizingRequestTest method testOverridingCreateRunner.
public void testOverridingCreateRunner() {
final Runner stubRunner = mock(Runner.class);
MemoizingRequest memoizingRequest = new MemoizingRequest(mockRequestDelegate) {
@Override
protected Runner createRunner(Request delegate) {
return stubRunner;
}
};
Runner firstRunner = memoizingRequest.getRunner();
Runner secondRunner = memoizingRequest.getRunner();
assertSame(stubRunner, firstRunner);
assertSame(firstRunner, secondRunner);
verifyZeroInteractions(mockRequestDelegate);
}
use of org.junit.runner.Runner in project bazel by bazelbuild.
the class JUnit4Runner method applyFilter.
private static Request applyFilter(Request request, Filter filter) throws NoTestsRemainException {
Runner runner = request.getRunner();
new SuiteTrimmingFilter(filter).apply(runner);
return Request.runner(runner);
}
use of org.junit.runner.Runner in project intellij-community by JetBrains.
the class JUnit46ClassesRequestBuilder method getClassesRequest.
public static Request getClassesRequest(final String suiteName, Class[] classes, Map classMethods, Class category) {
boolean canUseSuiteMethod = canUseSuiteMethod(classMethods);
try {
if (category != null) {
try {
Class.forName("org.junit.experimental.categories.Categories");
} catch (ClassNotFoundException e) {
throw new RuntimeException("Categories are not available");
}
}
Runner suite;
if (canUseSuiteMethod) {
try {
Class.forName("org.junit.experimental.categories.Categories");
suite = new IdeaSuite48(collectWrappedRunners(classes), suiteName, category);
} catch (ClassNotFoundException e) {
suite = new IdeaSuite(collectWrappedRunners(classes), suiteName);
}
} else {
final AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder(canUseSuiteMethod);
try {
Class.forName("org.junit.experimental.categories.Categories");
suite = new IdeaSuite48(builder, classes, suiteName, category);
} catch (ClassNotFoundException e) {
suite = new IdeaSuite(builder, classes, suiteName);
}
}
return Request.runner(suite);
} catch (InitializationError e) {
throw new RuntimeException(e);
}
}
Aggregations