use of org.junit.runner.Runner in project intellij-community by JetBrains.
the class JUnit4TestRunnerUtil method getParameterizedRequest.
private static Request getParameterizedRequest(final String parameterString, final String methodName, Class clazz, RunWith clazzAnnotation) {
if (clazzAnnotation == null)
return null;
final Class runnerClass = clazzAnnotation.value();
if (Parameterized.class.isAssignableFrom(runnerClass)) {
try {
if (methodName != null) {
final Method method = clazz.getMethod(methodName, new Class[0]);
if (method != null && !method.isAnnotationPresent(Test.class) && TestCase.class.isAssignableFrom(clazz)) {
return Request.runner(JUnit45ClassesRequestBuilder.createIgnoreAnnotationAndJUnit4ClassRunner(clazz));
}
}
//ignore for junit4.4 and <
Class.forName("org.junit.runners.BlockJUnit4ClassRunner");
final Constructor runnerConstructor = runnerClass.getConstructor(new Class[] { Class.class });
return Request.runner((Runner) runnerConstructor.newInstance(new Object[] { clazz })).filterWith(new Filter() {
public boolean shouldRun(Description description) {
final String descriptionMethodName = description.getMethodName();
//filter by params
if (parameterString != null && descriptionMethodName != null && !descriptionMethodName.endsWith(parameterString)) {
return false;
}
//filter only selected method
if (methodName != null && descriptionMethodName != null && //valid for any parameter for current method
!descriptionMethodName.startsWith(methodName + "[") && !descriptionMethodName.equals(methodName)) {
//if fork mode used, parameter is included in the name itself
return false;
}
return true;
}
public String describe() {
if (parameterString == null) {
return methodName + " with any parameter";
}
if (methodName == null) {
return "Parameter " + parameterString + " for any method";
}
return methodName + " with parameter " + parameterString;
}
});
} catch (Throwable throwable) {
//return simple method runner
}
}
return null;
}
use of org.junit.runner.Runner in project gerrit by GerritCodeReview.
the class ConfigSuite method runnersFor.
private static List<Runner> runnersFor(Class<?> clazz) {
Method defaultConfig = getDefaultConfig(clazz);
List<Method> configs = getConfigs(clazz);
Map<String, org.eclipse.jgit.lib.Config> configMap = callConfigMapMethod(getConfigMap(clazz), configs);
Field parameterField = getOnlyField(clazz, Parameter.class);
checkArgument(parameterField != null, "No @ConfigSuite.Parameter found");
Field nameField = getOnlyField(clazz, Name.class);
List<Runner> result = Lists.newArrayListWithCapacity(configs.size() + 1);
try {
result.add(new ConfigRunner(clazz, parameterField, nameField, null, callConfigMethod(defaultConfig)));
for (Method m : configs) {
result.add(new ConfigRunner(clazz, parameterField, nameField, m.getName(), callConfigMethod(m)));
}
for (Map.Entry<String, org.eclipse.jgit.lib.Config> e : configMap.entrySet()) {
result.add(new ConfigRunner(clazz, parameterField, nameField, e.getKey(), e.getValue()));
}
return result;
} catch (InitializationError e) {
System.err.println("Errors initializing runners:");
for (Throwable t : e.getCauses()) {
t.printStackTrace();
}
throw new RuntimeException(e);
}
}
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;
}
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();
}
}
}
use of org.junit.runner.Runner in project scout.rt by eclipse.
the class InteractiveTestSuite method run.
@Override
@SuppressWarnings({ "squid:S1181", "squid:S1166" })
public void run(final RunNotifier notifier) {
System.out.println("Started interactive test console. (Auto-closing in 30 seconds when no input is entered, assuming it is a ci-test-run)");
String lastLine = "";
while (true) {
try {
System.out.println("********");
System.out.println("[Enter fully qualified test class name, enter to repeat last test, '.' to exit]");
if (!checkIfHumanInterface()) {
return;
}
String line = new BufferedReader(new InputStreamReader(System.in)).readLine();
if (StringUtility.isNullOrEmpty(line)) {
if (!lastLine.isEmpty()) {
line = lastLine;
} else {
continue;
}
}
if (".".equalsIgnoreCase(line)) {
return;
}
lastLine = line;
Method runMethod;
try {
// NOSONAR
runMethod = m_annotatedClass.getMethod("run", Runner.class, RunNotifier.class);
} catch (Throwable t) {
runMethod = InteractiveTestSuite.class.getMethod("run", Runner.class, RunNotifier.class);
}
Class<?> testClass = Class.forName(line, true, m_annotatedClass.getClassLoader());
Runner runner = m_builder.safeRunnerForClass(testClass);
if (Modifier.isStatic(runMethod.getModifiers())) {
runMethod.invoke(null, runner, notifier);
} else {
runMethod.invoke(m_annotatedClass.newInstance(), runner, notifier);
}
} catch (Throwable ex) {
System.out.println("Cannot load test " + lastLine);
ex.printStackTrace(System.out);
}
}
}
Aggregations