private static Description getSuiteMethodDescription(Request request, Description description) throws NoSuchFieldException, IllegalAccessException { Field field; try { field = ClassRequest.class.getDeclaredField("fTestClass"); } catch (NoSuchFieldException e) { field = ClassRequest.class.getDeclaredField("testClass"); } field.setAccessible(true); final Description methodDescription = Description.createSuiteDescription((Class)field.get(request)); for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext();) { methodDescription.addChild((Description)iterator.next()); } description = methodDescription; return description; }
public Object getTestToStart(String[] args) { final Request request = JUnit4TestRunnerUtil.buildRequest(args, false); if (request == null) return null; final Runner testRunner = request.getRunner(); Description description = null; try { description = testRunner.getDescription(); if (request instanceof ClassRequest) { description = getSuiteMethodDescription(request, description); } else if (request instanceof FilterRequest) { description = getFilteredDescription(request, description); } } catch (Exception e) { //noinspection HardCodedStringLiteral System.err.println("Internal Error occured."); e.printStackTrace(System.err); } return description; }
private static Description getDescription(Request request, Runner testRunner) throws NoSuchFieldException, IllegalAccessException { Description description = testRunner.getDescription(); if (description == null) { System.err.println("Nothing found to run. Runner " + testRunner.getClass().getName() + " provides no description."); return null; } if (request instanceof ClassRequest) { description = getSuiteMethodDescription(request, description); } else if (request instanceof FilterRequest) { description = getFilteredDescription(request, description); } return description; }
private static Request createIgnoreIgnoredClassRequest(final Class clazz, final boolean recursively) throws ClassNotFoundException { Class.forName("org.junit.runners.BlockJUnit4ClassRunner"); //ignore IgnoreIgnored for junit4.4 and < return new ClassRequest(clazz) { public Runner getRunner() { try { return new IgnoreIgnoredTestJUnit4ClassRunner(clazz, recursively); } catch (Exception ignored) { //return super runner } return super.getRunner(); } }; }
private static Description getSuiteMethodDescription(Request request, Description description) throws NoSuchFieldException, IllegalAccessException { final Field field = ClassRequest.class.getDeclaredField("fTestClass"); field.setAccessible(true); final Description methodDescription = Description.createSuiteDescription((Class)field.get(request)); for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext();) { methodDescription.addChild((Description)iterator.next()); } description = methodDescription; return description; }
/** * Create a <code>Request</code> that, when processed, will run all the tests * in a class. The odd name is necessary because <code>class</code> is a reserved word. * * @param clazz the class containing the tests * @return a <code>Request</code> that will cause all tests in the class to be run */ public static Request aClass(Class<?> clazz) { return new ClassRequest(clazz); }
/** * Create a <code>Request</code> that, when processed, will run all the tests * in a class. If the class has a suite() method, it will be ignored. * * @param clazz the class containing the tests * @return a <code>Request</code> that will cause all tests in the class to be run */ public static Request classWithoutSuiteMethod(Class<?> clazz) { return new ClassRequest(clazz, false); }