Search in sources :

Example 56 with Runner

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);
}
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)

Example 57 with Runner

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);
}
Also used : Runner(org.junit.runner.Runner)

Example 58 with 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);
}
Also used : Runner(org.junit.runner.Runner) Request(org.junit.runner.Request)

Example 59 with Runner

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);
}
Also used : ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner) Runner(org.junit.runner.Runner) SuiteTrimmingFilter(com.google.testing.junit.junit4.runner.SuiteTrimmingFilter)

Example 60 with 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);
    }
}
Also used : ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner) Runner(org.junit.runner.Runner) AllDefaultPossibilitiesBuilder(org.junit.internal.builders.AllDefaultPossibilitiesBuilder) InitializationError(org.junit.runners.model.InitializationError)

Aggregations

Runner (org.junit.runner.Runner)106 Test (org.junit.Test)39 RunNotifier (org.junit.runner.notification.RunNotifier)22 ArrayList (java.util.ArrayList)18 Description (org.junit.runner.Description)18 JUnitCore (org.junit.runner.JUnitCore)18 ParentRunner (org.junit.runners.ParentRunner)16 Request (org.junit.runner.Request)15 Result (org.junit.runner.Result)13 Filter (org.junit.runner.manipulation.Filter)12 NoTestsRemainException (org.junit.runner.manipulation.NoTestsRemainException)12 InitializationError (org.junit.runners.model.InitializationError)10 Method (java.lang.reflect.Method)9 JUnit4ParameterizedTest (androidx.test.testing.fixtures.JUnit4ParameterizedTest)7 SuiteConfiguration (org.eclipse.reddeer.junit.internal.configuration.SuiteConfiguration)7 Failure (org.junit.runner.notification.Failure)7 ErrorReportingRunner (org.junit.internal.runners.ErrorReportingRunner)6 Filterable (org.junit.runner.manipulation.Filterable)6 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)6 Field (java.lang.reflect.Field)5