@Override public void run(RunNotifier notifier) { super.run(notifier); }
/** * Returns a {@link Statement}: apply all * static fields assignable to {@link TestRule} * annotated with {@link ClassRule}. * * @param statement the base statement * @return a RunRules statement if any class-level {@link Rule}s are * found, or the base statement */ private Statement withClassRules(Statement statement) { List<TestRule> classRules = classRules(); return classRules.isEmpty() ? statement : new RunRules(statement, classRules, getDescription()); }
private void validate() throws InitializationError { List<Throwable> errors = new ArrayList<Throwable>(); collectInitializationErrors(errors); if (!errors.isEmpty()) { throw new InitializationError(errors); } }
/** * Constructs a {@code Statement} to run all of the tests in the test class. Override to add pre-/post-processing. * Here is an outline of the implementation: * <ul> * <li>Call {@link #runChild(Object, RunNotifier)} on each object returned by {@link #getChildren()} (subject to any imposed filter and sort).</li> * <li>ALWAYS run all non-overridden {@code @BeforeClass} methods on this class * and superclasses before the previous step; if any throws an * Exception, stop execution and pass the exception on. * <li>ALWAYS run all non-overridden {@code @AfterClass} methods on this class * and superclasses before any of the previous steps; all AfterClass methods are * always executed: exceptions thrown by previous steps are combined, if * necessary, with exceptions from AfterClass methods into a * {@link MultipleFailureException}. * </ul> * * @return {@code Statement} */ protected Statement classBlock(final RunNotifier notifier) { Statement statement = childrenInvoker(notifier); statement = withBeforeClasses(statement); statement = withAfterClasses(statement); statement = withClassRules(statement); return statement; }
@Override public Description getDescription() { Description description = Description.createSuiteDescription(getName(), getRunnerAnnotations()); for (T child : getFilteredChildren()) { description.addChild(describeChild(child)); } return description; }
@Override public void run(final RunNotifier notifier) { EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription()); try { Statement statement = classBlock(notifier); statement.evaluate(); } catch (AssumptionViolatedException e) { testNotifier.fireTestIgnored(); } catch (StoppedByUserException e) { throw e; } catch (Throwable e) { testNotifier.addFailure(e); } }
for ( ParentRunner runner : runners ) runner.setScheduler( createScheduler( runner.getDescription(), commonPool, doParallel, concurrencyLimit ) ); for ( ParentRunner runner : runners ) runner.setScheduler( createScheduler( runner.getDescription(), pool, doParallel, BalancerFactory.createInfinitePermitsBalancer() ) );
@Override public Description getDescription() { return delegate.getDescription(); }
@Override public void filter(Filter filter) throws NoTestsRemainException { boolean noRuleTests = false; try { ruleTests.filter(filter); } catch (NoTestsRemainException e) { noRuleTests = true; } boolean noUnitTests = false; try { unitTests.filter(filter); } catch (NoTestsRemainException e) { noUnitTests = false; } if (noRuleTests && noUnitTests) { throw new NoTestsRemainException(); } }
private void applyValidators(List<Throwable> errors) { if (getTestClass().getJavaClass() != null) { for (TestClassValidator each : VALIDATORS) { errors.addAll(each.validateTestClass(getTestClass())); } } }
private static Runner parallelize(Runner runner) { if (runner instanceof ParentRunner) { ((ParentRunner<?>) runner).setScheduler(new RunnerScheduler() { private final ExecutorService fService = Executors.newCachedThreadPool(); public void schedule(Runnable childStatement) { fService.submit(childStatement); } public void finished() { try { fService.shutdown(); fService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { e.printStackTrace(System.err); } } }); } return runner; }
@Override protected Statement childrenInvoker(RunNotifier notifier) { final Statement features = super.childrenInvoker(notifier); return new Statement() { @Override public void evaluate() throws Throwable { features.evaluate(); bus.send(new TestRunFinished(bus.getTime())); } }; }
@Override protected String getName() { return root ? super.getName() : baseFolder.getName(); } }
@Override protected List<TestRule> classRules() { List<TestRule> rules = super.classRules(); rules.add(tests.getRule()); return rules; }
@Override protected Statement classBlock(RunNotifier notifier) { final Statement statement = super.classBlock(notifier); return new Statement() { @Override public void evaluate() throws Throwable { try { statement.evaluate(); } finally { cache.clear(getTestClass().getJavaClass()); } } }; }
@Override public Description getDescription() { Class<?> clazz = getTestClass().getJavaClass(); Description description; // if subclass overrides `getName()` then we should use it // to maintain backwards compatibility with JUnit 4.12 if (clazz == null || !clazz.getName().equals(getName())) { description = Description.createSuiteDescription(getName(), getRunnerAnnotations()); } else { description = Description.createSuiteDescription(clazz, getRunnerAnnotations()); } for (T child : getFilteredChildren()) { description.addChild(describeChild(child)); } return description; }
Statement statement = childrenInvoker(notifier); if (!areAllChildrenIgnored()) { statement = withBeforeClasses(statement); statement = withAfterClasses(statement); statement = withClassRules(statement); statement = withInterruptIsolation(statement);
@Override public void run(final RunNotifier notifier) { EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription()); testNotifier.fireTestSuiteStarted(); try { Statement statement = classBlock(notifier); statement.evaluate(); } catch (AssumptionViolatedException e) { testNotifier.addFailedAssumption(e); } catch (StoppedByUserException e) { throw e; } catch (Throwable e) { testNotifier.addFailure(e); } finally { testNotifier.fireTestSuiteFinished(); } }
@Override public void apply( Object child ) throws NoTestsRemainException { super.apply( child ); if ( child instanceof ParentRunner ) { ParentRunner runner = ( ParentRunner ) child; if ( !isThreadSafe( runner ) ) { runner.setScheduler( notThreadSafeTests.newRunnerScheduler() ); } else if ( child instanceof Suite ) { nestedSuites.add( (Suite) child ); } else { ParentRunner parentRunner = (ParentRunner) child; nestedClasses.add( parentRunner ); nestedClassesChildren += parentRunner.getDescription().getChildren().size(); } } }
@Override public Description getDescription() { return delegate.getDescription(); }