Search in sources :

Example 1 with Runner

use of org.junit.runner.Runner in project buck by facebook.

the class JUnitRunner method run.

@Override
public void run() throws Throwable {
    Level stdOutLogLevel = Level.INFO;
    Level stdErrLogLevel = Level.WARNING;
    String unparsedStdOutLogLevel = System.getProperty(STD_OUT_LOG_LEVEL_PROPERTY);
    String unparsedStdErrLogLevel = System.getProperty(STD_ERR_LOG_LEVEL_PROPERTY);
    if (unparsedStdOutLogLevel != null) {
        stdOutLogLevel = Level.parse(unparsedStdOutLogLevel);
    }
    if (unparsedStdErrLogLevel != null) {
        stdErrLogLevel = Level.parse(unparsedStdErrLogLevel);
    }
    for (String className : testClassNames) {
        final Class<?> testClass = Class.forName(className);
        List<TestResult> results = new ArrayList<>();
        RecordingFilter filter = new RecordingFilter();
        if (mightBeATestClass(testClass)) {
            JUnitCore jUnitCore = new JUnitCore();
            Runner suite = new Computer().getSuite(createRunnerBuilder(), new Class<?>[] { testClass });
            Request request = Request.runner(suite);
            request = request.filterWith(filter);
            jUnitCore.addListener(new TestListener(results, stdOutLogLevel, stdErrLogLevel));
            jUnitCore.run(request);
        }
        // Combine the results with the tests we filtered out
        List<TestResult> actualResults = combineResults(results, filter.filteredOut);
        writeResult(className, actualResults);
    }
}
Also used : Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) ArrayList(java.util.ArrayList) Computer(org.junit.runner.Computer) Request(org.junit.runner.Request) Level(java.util.logging.Level)

Example 2 with Runner

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

the class ParentRunnerFilteringTest method testSuiteFilteringWithUnmodifyableChildList.

@Test
public void testSuiteFilteringWithUnmodifyableChildList() throws Exception {
    Runner runner = Request.aClass(ExampleSuiteWithUnmodifyableChildList.class).getRunner();
    Filter filter = notThisMethodName("test1");
    try {
        filter.apply(runner);
    } catch (NoTestsRemainException e) {
        return;
    }
    fail("Expected 'NoTestsRemainException' due to complete filtering");
}
Also used : Runner(org.junit.runner.Runner) Filter(org.junit.runner.manipulation.Filter) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) Test(org.junit.Test)

Example 3 with Runner

use of org.junit.runner.Runner in project cucumber-jvm by cucumber.

the class ExamplesRunner method buildRunners.

private static List<Runner> buildRunners(Runtime runtime, CucumberExamples cucumberExamples, JUnitReporter jUnitReporter) {
    List<Runner> runners = new ArrayList<Runner>();
    List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
    for (CucumberScenario scenario : exampleScenarios) {
        try {
            ExecutionUnitRunner exampleScenarioRunner = new ExecutionUnitRunner(runtime, scenario, jUnitReporter);
            runners.add(exampleScenarioRunner);
        } catch (InitializationError initializationError) {
            initializationError.printStackTrace();
        }
    }
    return runners;
}
Also used : Runner(org.junit.runner.Runner) InitializationError(org.junit.runners.model.InitializationError) ArrayList(java.util.ArrayList) CucumberScenario(cucumber.runtime.model.CucumberScenario)

Example 4 with Runner

use of org.junit.runner.Runner in project intellij-community by JetBrains.

the class IdeaSuite method skipSuiteComponents.

private void skipSuiteComponents(Set allNames, Object child) {
    try {
        if (child instanceof Suite) {
            final Method getChildrenMethod = Suite.class.getDeclaredMethod("getChildren", new Class[0]);
            getChildrenMethod.setAccessible(true);
            final List tests = (List) getChildrenMethod.invoke(child, new Object[0]);
            for (Iterator suiteIterator = tests.iterator(); suiteIterator.hasNext(); ) {
                final String displayName = describeChild((Runner) suiteIterator.next()).getDisplayName();
                if (allNames.contains(displayName)) {
                    allNames.remove(displayName);
                }
            }
        } else if (child instanceof SuiteMethod) {
            final Method getChildrenMethod = JUnit38ClassRunner.class.getDeclaredMethod("getTest", new Class[0]);
            getChildrenMethod.setAccessible(true);
            final Test test = (Test) getChildrenMethod.invoke(child, new Object[0]);
            if (test instanceof TestSuite) {
                final Enumeration tests = ((TestSuite) test).tests();
                while (tests.hasMoreElements()) {
                    final Test t = (Test) tests.nextElement();
                    if (t instanceof TestSuite) {
                        final String testDescription = ((TestSuite) t).getName();
                        if (allNames.contains(testDescription)) {
                            allNames.remove(testDescription);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JUnit38ClassRunner(org.junit.internal.runners.JUnit38ClassRunner) Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) JUnit38ClassRunner(org.junit.internal.runners.JUnit38ClassRunner) SuiteMethod(org.junit.internal.runners.SuiteMethod) SuiteMethod(org.junit.internal.runners.SuiteMethod) Method(java.lang.reflect.Method) TestSuite(junit.framework.TestSuite) Suite(org.junit.runners.Suite) TestSuite(junit.framework.TestSuite) Test(junit.framework.Test)

Example 5 with Runner

use of org.junit.runner.Runner in project intellij-community by JetBrains.

the class IdeaSuite method getDescription.

public Description getDescription() {
    Description description = Description.createSuiteDescription(myName, getTestClass().getAnnotations());
    try {
        final Method getFilteredChildrenMethod = ParentRunner.class.getDeclaredMethod("getFilteredChildren", new Class[0]);
        getFilteredChildrenMethod.setAccessible(true);
        Collection filteredChildren = (Collection) getFilteredChildrenMethod.invoke(this, new Object[0]);
        for (Iterator iterator = filteredChildren.iterator(); iterator.hasNext(); ) {
            Object child = iterator.next();
            description.addChild(describeChild((Runner) child));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return description;
}
Also used : JUnit38ClassRunner(org.junit.internal.runners.JUnit38ClassRunner) Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) Description(org.junit.runner.Description) SuiteMethod(org.junit.internal.runners.SuiteMethod) Method(java.lang.reflect.Method)

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