Search in sources :

Example 31 with Runner

use of org.junit.runner.Runner in project gradle by gradle.

the class IgnoredTestDescriptorProvider method getAllDescriptions.

List<Description> getAllDescriptions(Description description, String className) {
    final AllExceptIgnoredTestRunnerBuilder allExceptIgnoredTestRunnerBuilder = new AllExceptIgnoredTestRunnerBuilder();
    try {
        final Class<?> testClass = description.getClass().getClassLoader().loadClass(className);
        Runner runner = allExceptIgnoredTestRunnerBuilder.runnerForClass(testClass);
        if (runner == null) {
            // fall back to default runner
            runner = Request.aClass(testClass).getRunner();
        }
        final Description runnerDescription = runner.getDescription();
        return runnerDescription.getChildren();
    } catch (Throwable throwable) {
        throw new TestSuiteExecutionException(String.format("Unable to process Ignored class %s.", className), throwable);
    }
}
Also used : Runner(org.junit.runner.Runner) Description(org.junit.runner.Description) TestSuiteExecutionException(org.gradle.api.internal.tasks.testing.TestSuiteExecutionException)

Example 32 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 33 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 34 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 35 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)64 Test (org.junit.Test)21 Description (org.junit.runner.Description)14 ParentRunner (org.junit.runners.ParentRunner)13 ArrayList (java.util.ArrayList)12 JUnitCore (org.junit.runner.JUnitCore)11 Request (org.junit.runner.Request)11 RunNotifier (org.junit.runner.notification.RunNotifier)11 Filter (org.junit.runner.manipulation.Filter)10 NoTestsRemainException (org.junit.runner.manipulation.NoTestsRemainException)9 Result (org.junit.runner.Result)8 Method (java.lang.reflect.Method)7 Failure (org.junit.runner.notification.Failure)7 InitializationError (org.junit.runners.model.InitializationError)7 JUnit38ClassRunner (org.junit.internal.runners.JUnit38ClassRunner)5 RunnerSpy (org.junit.runner.RunnerSpy)5 LinkedList (java.util.LinkedList)4 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)4 File (java.io.File)3 ImmutableMap (com.google.common.collect.ImmutableMap)2