Search in sources :

Example 41 with Runner

use of org.junit.runner.Runner in project junit5 by junit-team.

the class TestClassRequestResolver method determineRunnerTestDescriptor.

private RunnerTestDescriptor determineRunnerTestDescriptor(Class<?> testClass, Runner runner, List<RunnerTestDescriptorAwareFilter> filters, UniqueId engineId) {
    RunnerTestDescriptor runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, runner, engineId);
    if (!filters.isEmpty()) {
        if (runner instanceof Filterable) {
            Filter filter = createOrFilter(filters, runnerTestDescriptor);
            Runner filteredRunner = runnerTestDescriptor.toRequest().filterWith(filter).getRunner();
            runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, filteredRunner, engineId);
        } else {
            Runner runnerToReport = (runner instanceof RunnerDecorator) ? ((RunnerDecorator) runner).getDecoratedRunner() : runner;
            logger.warn(() -> // 
            "Runner " + runnerToReport.getClass().getName() + " (used on " + testClass.getName() + // 
            ") does not support filtering" + " and will therefore be run completely.");
        }
    }
    return runnerTestDescriptor;
}
Also used : RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) Runner(org.junit.runner.Runner) Filter(org.junit.runner.manipulation.Filter) Filterable(org.junit.runner.manipulation.Filterable)

Example 42 with Runner

use of org.junit.runner.Runner in project pinpoint by naver.

the class ForkedPinpointPluginTest method runTests.

private static Result runTests(Class<?> testClass, String testId) throws InitializationError {
    JUnitCore junit = new JUnitCore();
    junit.addListener(new PrintListener());
    Runner runner = new ForkedPinpointPluginTestRunner(testClass, testId);
    Result result = junit.run(runner);
    return result;
}
Also used : Runner(org.junit.runner.Runner) PrintListener(com.navercorp.pinpoint.test.plugin.shared.PrintListener) JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result)

Example 43 with Runner

use of org.junit.runner.Runner in project pinpoint by naver.

the class PinpointPluginTestSuite method filter.

@Override
public void filter(Filter filter) throws NoTestsRemainException {
    synchronized (childrenLock) {
        List<Runner> children = new ArrayList<>(getFilteredChildren());
        for (Iterator<Runner> iter = children.iterator(); iter.hasNext(); ) {
            Runner each = iter.next();
            if (shouldRun(filter, each)) {
                try {
                    filter.apply(each);
                } catch (NoTestsRemainException e) {
                    iter.remove();
                }
            } else {
                iter.remove();
            }
        }
        filteredChildren = Collections.unmodifiableCollection(children);
        if (filteredChildren.isEmpty()) {
            throw new NoTestsRemainException();
        }
    }
}
Also used : Runner(org.junit.runner.Runner) ArrayList(java.util.ArrayList) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException)

Example 44 with Runner

use of org.junit.runner.Runner in project ceylon by eclipse.

the class CeylonModuleRunner method makeModuleRunnerInNewJvm.

private void makeModuleRunnerInNewJvm(final ModuleSpecifier module) {
    final Description description = Description.createTestDescription(getClass(), "Run " + module.module() + " in new JVM");
    Runner runner = new Runner() {

        @Override
        public Description getDescription() {
            return description;
        }

        @Override
        public void run(RunNotifier notifier) {
            notifier.fireTestStarted(description);
            try {
                String moduleName = module.module();
                String version = Module.DEFAULT_MODULE_NAME.equals(moduleName) ? null : module.version();
                String runClass = module.runClass();
                if (runClass.isEmpty())
                    runClass = moduleName + ".run_";
                runModuleInNewJvm(moduleName, version, runClass);
            } catch (Exception x) {
                x.printStackTrace();
                notifier.fireTestFailure(new Failure(description, x));
            }
            notifier.fireTestFinished(description);
        }
    };
    children.put(runner, description);
}
Also used : Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) Description(org.junit.runner.Description) RunNotifier(org.junit.runner.notification.RunNotifier) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) Failure(org.junit.runner.notification.Failure)

Example 45 with Runner

use of org.junit.runner.Runner in project ceylon by eclipse.

the class CeylonModuleRunner method postCompile.

private void postCompile(Context context, ErrorCollector listener, String moduleName, File srcDir, String[] dependencies, Set<String> removeAtRuntime, String[] modulesUsingCheckFunction, String[] modulesUsingCheckModule) throws Exception {
    // now fetch stuff from the context
    PhasedUnits phasedUnits = LanguageCompiler.getPhasedUnitsInstance(context);
    List<Runner> moduleRunners = new LinkedList<Runner>();
    // Get a class loader for the car
    // XXX Need to use CMR if the module has dependencies
    URL[] carUrls = getCarUrls(moduleName, dependencies, removeAtRuntime, outRepo);
    URLClassLoader cl = classLoaderForModule(carUrls);
    Runnable moduleInitialiser = getModuleInitialiser(moduleName, carUrls, dependencies, removeAtRuntime, cl);
    if (cl != null) {
        loadCompiledTests(moduleRunners, srcDir, cl, phasedUnits, moduleName, modulesUsingCheckFunction, modulesUsingCheckModule);
    }
    CeylonTestGroup ceylonTestGroup = new CeylonTestGroup(moduleRunners, moduleName, moduleInitialiser);
    children.put(ceylonTestGroup, ceylonTestGroup.getDescription());
}
Also used : Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) URLClassLoader(java.net.URLClassLoader) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) LinkedList(java.util.LinkedList) URL(java.net.URL)

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