public JUnit4TestAdapter(final Class<?> newTestClass, JUnit4TestAdapterCache cache) { fCache = cache; fNewTestClass = newTestClass; fRunner = Request.classWithoutSuiteMethod(newTestClass).getRunner(); }
/** * Run all the tests contained in <code>request</code>. * * @param request the request describing tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Request request) { return run(request.getRunner()); }
/** * Run all the tests contained in <code>request</code>. * * @param request the request describing tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Request request) { return run(request.getRunner()); }
public JUnit4TestAdapter(final Class<?> newTestClass, JUnit4TestAdapterCache cache) { fCache = cache; fNewTestClass = newTestClass; fRunner = Request.classWithoutSuiteMethod(newTestClass).getRunner(); }
@Override protected Runner createRunner() { Runner runner = request.getRunner(); try { ordering.apply(runner); } catch (InvalidOrderingException e) { return new ErrorReportingRunner(ordering.getClass(), e); } return runner; } }
private List<Description> findLeaves(Request request) { List<Description> results = new ArrayList<Description>(); findLeaves(null, request.getRunner().getDescription(), results); return results; }
@Override public Runner getRunner() { try { Runner runner = request.getRunner(); fFilter.apply(runner); return runner; } catch (NoTestsRemainException e) { return new ErrorReportingRunner(Filter.class, new Exception(String .format("No tests found matching %s from %s", fFilter .describe(), request.toString()))); } } }
private List<Description> findLeaves(Request request) { List<Description> results = new ArrayList<Description>(); findLeaves(null, request.getRunner().getDescription(), results); return results; }
@Override public Runner getRunner() { try { Runner runner = fRequest.getRunner(); fFilter.apply(runner); return runner; } catch (NoTestsRemainException e) { return new ErrorReportingRunner(Filter.class, new Exception(String .format("No tests found matching %s from %s", fFilter .describe(), fRequest.toString()))); } } }
@Override public Runner getRunner() { Runner runner = request.getRunner(); new Sorter(comparator).apply(runner); return runner; } }
@Override public Runner getRunner() { Runner runner = fRequest.getRunner(); new Sorter(fComparator).apply(runner); return runner; } }
/** * Creates a {@link Filter}. * * A filter specification is of the form "package.of.FilterFactory=args-to-filter-factory" or * "package.of.FilterFactory". * * @param request the request that will be filtered * @param filterSpec the filter specification * @throws org.junit.runner.FilterFactory.FilterNotCreatedException */ public static Filter createFilterFromFilterSpec(Request request, String filterSpec) throws FilterFactory.FilterNotCreatedException { Description topLevelDescription = request.getRunner().getDescription(); String[] tuple; if (filterSpec.contains("=")) { tuple = filterSpec.split("=", 2); } else { tuple = new String[]{ filterSpec, "" }; } return createFilter(tuple[0], new FilterFactoryParams(topLevelDescription, tuple[1])); }
public static Failure runTestWithExpectedFailure(final Class<?> test) { JUnitCore junitCore = new JUnitCore(); Result result = junitCore.run(Request.aClass(test).getRunner()); List<Failure> failures = result.getFailures(); assertThat(failures).hasSize(1); return failures.get(0); }
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(); }
public static Result runTestWithValidation(final Class<?> test) { JUnitCore junitCore = new JUnitCore(); Result result = junitCore.run(Request.aClass(test).getRunner()); List<Failure> failures = result.getFailures(); if (!failures.isEmpty()) { Failure firstFailure = failures.get(0); throw new AssertionError(firstFailure.getException()); } assertThat(result.wasSuccessful()).isTrue(); return result; }
/** * 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 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(fHistory.listener()); return core.run(sortRequest(request).getRunner()); }
public static List<Failure> runTestWithExpectedFailures(final Class<?> test) { JUnitCore junitCore = new JUnitCore(); Result result = junitCore.run(Request.aClass(test).getRunner()); List<Failure> failures = result.getFailures(); assertThat(failures).isNotEmpty(); return failures; } }
@Test public void testWorkingCategoryAndParameterized() { Request request = Request.aClass(WorkingCategoryClass.class); ExposedParameterized runner = (ExposedParameterized) request.getRunner(); request = request.filterWith(new CategoryFilter((ExposedGetAnnotations) runner.getChildren().get(0))); Result result = new JUnitCore().run(request); assertEquals(2, result.getRunCount()); }
@Test public void testBrokenCategoryAndParameterized() { Request request = Request.aClass(BrokenCategoryClass.class); ExposedParameterized runner = (ExposedParameterized) request.getRunner(); request = request.filterWith(new CategoryFilter( (ExposedBlockJUnit4ClassRunnerWithParameters) runner.getChildren().get(0))); Result result = new JUnitCore().run(request); assertEquals( "Yeah!! This might actually mean we've upgraded to JUnit 4.13. Hurry up already and delete this hack.", 1, result.getRunCount()); }