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);
}
}
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");
}
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;
}
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();
}
}
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;
}
Aggregations