Refine search
JUnitCore core = new JUnitCore(); core.addListener(new RL()); Request r = Request.aClass(testCase); return core.run(r.filterWith(new Filter() {
private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
/** * Run all the tests in <code>classes</code>. * * @param computer Helps construct Runners from classes * @param classes the classes containing tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Computer computer, Class<?>... classes) { return run(Request.classes(computer, classes)); }
public JUnit4TestAdapter(final Class<?> newTestClass, JUnit4TestAdapterCache cache) { fCache = cache; fNewTestClass = newTestClass; fRunner = Request.classWithoutSuiteMethod(newTestClass).getRunner(); }
/** * Create a <code>Request</code> that, when processed, will run a single test. * This is done by filtering out all other tests. This method is used to support rerunning * single tests. * * @param clazz the class of the test * @param methodName the name of the test * @return a <code>Request</code> that will cause a single test be run */ public static Request method(Class<?> clazz, String methodName) { Description method = Description.createTestDescription(clazz, methodName); return Request.aClass(clazz).filterWith(method); }
private static void runTest(String test) { try { String[] classAndMethod = test.split("#"); System.out.println(test); Request request = Request.method(Class.forName(classAndMethod[0]), classAndMethod[1]); JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); junit.run(request); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
private Runnable createRunnable(Class<?> testClass, String testMathod) { return () -> { LOGGER.info(Thread.currentThread().getName() + " Parallel Junit test- *Start. Time = " + now()); Result result = (new JUnitCore()).run(Request.method(testClass, testMathod)); LOGGER.info(Thread.currentThread().getName() + " Parallel Junit test- * End. Time = " + now()); if (result.wasSuccessful()) { passedCounter.incrementAndGet(); } else { failedCounter.incrementAndGet(); } }; }
RichLogger logger = new RichLogger(loggers, settings, testClassName); EventDispatcher ed = new EventDispatcher(logger, eventHandler, settings, fingerprint); JUnitCore ju = new JUnitCore(); ju.addListener(ed); if (runListener != null) { ju.addListener(createRunListener(runListener)); Class<?> cl = testClassLoader.loadClass(testClassName); if(shouldRun(fingerprint, cl, settings)) { Request request = Request.classes(cl); if(globPatterns.size() > 0) request = new SilentFilterRequest(request, new GlobFilter(settings, globPatterns)); if(testFilter.length() > 0) request = new SilentFilterRequest(request, new TestFilter(testFilter, ed));
/** * Run all the tests contained in <code>request</code>. * * This variant should be used if {@code core} has attached listeners that this * run should notify. * * @param request the request describing tests * @param core a JUnitCore to delegate to. * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Request request, JUnitCore core) { core.addListener(history.listener()); return core.run(sortRequest(request).getRunner()); }
/** * Run all the tests in <code>classes</code>. * * @param classes the classes containing tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Class<?>... classes) { return run(Request.classes(defaultComputer(), classes)); }
public static void run(Configuration configuration, Class<?> clazz, String methodName) { try { Request request = null; if (clazz!=null && methodName!=null) { request = Request.method(clazz, methodName); } else { Suite suite = new Suite(new JUnit4Builder(), API_TEST_CLASSES); request = Request.runner(suite); } Configuration originalConfiguration = WorkflowTest.cachedConfiguration; WorkflowTest.cachedConfiguration = configuration; JUnitCore junitCore = new JUnitCore(); Result result = junitCore.run(request); WorkflowTest.cachedConfiguration = originalConfiguration; checkResult(result); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Run a single method test * * @param jUnitCore * @param className * @param method */ protected void runMethodOnly(JUnitCore jUnitCore, String className, String method) { try { jUnitCore.run(Request.method(Class.forName(className), method)); } catch (ClassNotFoundException e) { error("Test class not found: " + className); printStackTrace(e); } }
@Override protected Runner createRunner() { Runner runner = request.getRunner(); try { ordering.apply(runner); } catch (InvalidOrderingException e) { return new ErrorReportingRunner(ordering.getClass(), e); } return runner; } }
/** * Returns a Request that only runs tests whose {@link Description} * matches the given description. * * <p>Returns an empty {@code Request} if {@code desiredDescription} is not a single test and filters all but the single * test if {@code desiredDescription} is a single test.</p> * * @param desiredDescription {@code Description} of those tests that should be run * @return the filtered Request */ public Request filterWith(Description desiredDescription) { return filterWith(Filter.matchMethodDescription(desiredDescription)); }
private RunnerTestDescriptor determineRunnerTestDescriptor(Class<?> testClass, Runner runner, List<RunnerTestDescriptorAwareFilter> filters, UniqueId engineId) { RunnerTestDescriptor runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, runner, engineId); if (!filters.isEmpty()) { if (runner instanceof Filterable) { Filter filter = createOrFilter(filters, runnerTestDescriptor); Runner filteredRunner = runnerTestDescriptor.toRequest().filterWith(filter).getRunner(); runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, filteredRunner, engineId); } else { Runner runnerToReport = (runner instanceof RunnerDecorator) ? ((RunnerDecorator) runner).getDecoratedRunner() : runner; logger.warn(() -> "Runner " + runnerToReport.getClass().getName() // + " (used on " + testClass.getName() + ") does not support filtering" // + " and will therefore be run completely."); } } return runnerTestDescriptor; }
private JUnit4Runner(Class clazz, String methodName, int startInclusive, int endExclusive) { this.request = Request.classes(clazz).filterWith( createFilter(methodName, startInclusive, endExclusive) ); }
/** * Create a <code>Request</code> that, when processed, will run all the tests * in a set of classes with the default <code>Computer</code>. * * @param classes the classes containing the tests * @return a <code>Request</code> that will cause all tests in the classes to be run */ public static Request classes(Class<?>... classes) { return classes(JUnitCore.defaultComputer(), classes); }