Search in sources :

Example 56 with Request

use of org.junit.runner.Request 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()) {
        TestSelectionMatcher matcher = new TestSelectionMatcher(options.getIncludedTests(), 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);
}
Also used : Runner(org.junit.runner.Runner) TestSelectionMatcher(org.gradle.api.internal.tasks.testing.filter.TestSelectionMatcher) RunNotifier(org.junit.runner.notification.RunNotifier) Filter(org.junit.runner.manipulation.Filter) Filterable(org.junit.runner.manipulation.Filterable) ArrayList(java.util.ArrayList) Request(org.junit.runner.Request) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException)

Aggregations

Request (org.junit.runner.Request)56 Test (org.junit.Test)37 JUnitCore (org.junit.runner.JUnitCore)33 Result (org.junit.runner.Result)23 Description (org.junit.runner.Description)20 Runner (org.junit.runner.Runner)9 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)8 PrintableResult.testResult (org.junit.experimental.results.PrintableResult.testResult)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Filter (org.junit.runner.manipulation.Filter)6 Failure (org.junit.runner.notification.Failure)6 RunListener (org.junit.runner.notification.RunListener)6 OutputStream (java.io.OutputStream)5 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 InOrder (org.mockito.InOrder)4 Computer (org.junit.runner.Computer)3 RunNotifier (org.junit.runner.notification.RunNotifier)3