Request (String[] suiteClassNames, final String programParameters, boolean notForked) { if (suiteClassNames.length == 0) { return null; } ArrayList<Class<?>> result = new ArrayList<>(); for (String suiteClassName : suiteClassNames) { if (suiteClassName.charAt(0) == '@') { // all tests in the package specified try { final Map<String, Set<String>> classMethods = new HashMap<>(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(suiteClassName.substring(1)), StandardCharsets.UTF_8))) { final String packageName = reader.readLine(); if (packageName == null) return null; final String categoryName = reader.readLine(); final Class<?> category = categoryName != null && !categoryName.isEmpty() ? loadTestClass(categoryName) : null; final String filters = reader.readLine(); String line; while ((line = reader.readLine()) != null) { String className = line; final int idx = line.indexOf(','); if (idx != -1) { className = line.substring(0, idx); Set<String> methodNames = classMethods.get(className); if (methodNames == null) { methodNames = new HashSet<>(); classMethods.put(className, methodNames); } methodNames.add(line.substring(idx + 1)); } appendTestClass(result, className); } String suiteName = packageName.isEmpty() ? "<default package>" : packageName; Class<?>[] classes = getArrayOfClasses(result); if (classes.length == 0) { System.out.println(TestRunnerUtil.testsFoundInPackageMessage(0, suiteName)); return null; } Request allClasses; try { Class.forName("org.junit.runner.Computer"); allClasses = JUnit46ClassesRequestBuilder.getClassesRequest(suiteName, classes, classMethods, category); } catch (ClassNotFoundException | NoSuchMethodError e) { allClasses = getClassRequestsUsing44API(suiteName, classes); } return classMethods.isEmpty() ? allClasses : allClasses.filterWith(new Filter() { @Override public boolean shouldRun(Description description) { if (description.isTest()) { final Set<String> methods = classMethods.get(JUnit4ReflectionUtil.getClassName(description)); if (methods == null) { return true; } String methodName = JUnit4ReflectionUtil.getMethodName(description); if (methods.contains(methodName)) { return true; } if (programParameters != null) { return methodName.endsWith(programParameters) && methods.contains(methodName.substring(0, methodName.length() - programParameters.length())); } final Class<?> testClass = description.getTestClass(); if (testClass != null) { final RunWith classAnnotation = testClass.getAnnotation(RunWith.class); if (classAnnotation != null && isParameterized(methodName, testClass)) { final int idx = methodName.indexOf("["); if (idx > -1) { return methods.contains(methodName.substring(0, idx)); } } } return false; } return true; } @Override public String describe() { return "Tests"; } }); } } catch (IOException e) { e.printStackTrace(); System.exit(1); } } else { int index = suiteClassName.indexOf(','); if (index != -1) { final Class<?> clazz = loadTestClass(suiteClassName.substring(0, index)); final String methodName = suiteClassName.substring(index + 1); final RunWith clazzAnnotation = clazz.getAnnotation(RunWith.class); final Description testMethodDescription = Description.createTestDescription(clazz, methodName); if (clazzAnnotation == null) { //do not override external runners try { final Method method = clazz.getMethod(methodName); if (notForked && (method.getAnnotation(Ignore.class) != null || clazz.getAnnotation(Ignore.class) != null)) { //override ignored case only final Request classRequest = JUnit45ClassesRequestBuilder.createIgnoreIgnoredClassRequest(clazz, true); final Filter ignoredTestFilter = Filter.matchMethodDescription(testMethodDescription); return classRequest.filterWith(new Filter() { @Override public boolean shouldRun(Description description) { return ignoredTestFilter.shouldRun(description); } @Override public String describe() { return "Ignored " + methodName; } }); } } catch (Throwable ignored) { //return simple method runner } } else { final Request request = getParameterizedRequest(programParameters, methodName, clazz, clazzAnnotation); if (request != null) { return request; } } try { if (!methodName.equals("suite")) { clazz.getMethod("suite"); // check method existence return Request.classWithoutSuiteMethod(clazz).filterWith(testMethodDescription); } } catch (Throwable e) { //ignore } final Filter methodFilter; try { methodFilter = Filter.matchMethodDescription(testMethodDescription); } catch (NoSuchMethodError e) { return Request.method(clazz, methodName); } return Request.aClass(clazz).filterWith(new Filter() { @Override public boolean shouldRun(Description description) { if (description.isTest() && description.getDisplayName().startsWith("warning(junit.framework.TestSuite$")) { return true; } if (description.isTest() && isParameterizedMethodName(description.getMethodName(), methodName)) { return true; } return methodFilter.shouldRun(description); } @Override public String describe() { return methodFilter.describe(); } }); } else if (programParameters != null && suiteClassNames.length == 1) { final Class<?> clazz = loadTestClass(suiteClassName); if (clazz != null) { final RunWith clazzAnnotation = clazz.getAnnotation(RunWith.class); final Request request = getParameterizedRequest(programParameters, null, clazz, clazzAnnotation); if (request != null) { return request; } } } appendTestClass(result, suiteClassName); } } if (result.size() == 1) { final Class<?> clazz = result.get(0); try { if (clazz.getAnnotation(Ignore.class) != null) { //override ignored case only return JUnit45ClassesRequestBuilder.createIgnoreIgnoredClassRequest(clazz, false); } } catch (ClassNotFoundException e) { //return simple class runner } return Request.aClass(clazz); } return Request.classes(getArrayOfClasses(result)); }