@Override
 public RunResult invoke(Object forkTestSet) {
   ReporterFactory reporterFactory = providerParameters.getReporterFactory();
   RunListener listener = reporterFactory.createReporter();
   Runner runner = new Runner(tags);
   TestBlock rootBlock = runner.defineTests(getSuites());
   List<Reporter> reporters =
       Arrays.asList(new DefaultReporter(), new CuppaSurefireReporter(listener));
   runner.run(rootBlock, new CompositeReporter(reporters));
   return reporterFactory.close();
 }
Beispiel #2
0
  private RunResult invokeAllTests(TestsToRun testsToRun) {
    RunResult runResult;
    ReporterFactory reporterFactory = parameters.getReporterFactory();
    try {
      RunListener runListener = reporterFactory.createReporter();
      launcher.registerTestExecutionListeners(new RunListenerAdapter(runListener));

      for (Class<?> testClass : testsToRun) {
        invokeSingleClass(testClass, runListener);
      }
    } finally {
      runResult = reporterFactory.close();
    }
    return runResult;
  }
  // Mostly taken from Junit4Provider.java
  public RunResult invokeJunit4(Class<?> clazz, String requestedTestMethod)
      throws TestSetFailedException {

    final ReporterFactory reporterFactory = providerParameters.getReporterFactory();

    RunListener reporter = reporterFactory.createReporter();

    ConsoleOutputCapture.startCapture((ConsoleOutputReceiver) reporter);

    JUnit4RunListener jUnit4TestSetReporter = new JUnit4RunListener(reporter);

    Result result = new Result();
    RunNotifier listeners = getRunNotifier(jUnit4TestSetReporter, result, customRunListeners);

    listeners.fireTestRunStarted(Description.createTestDescription(clazz, requestedTestMethod));

    final ReportEntry report =
        new SimpleReportEntry(
            getClass().getName() + "." + requestedTestMethod,
            clazz.getName() + "." + requestedTestMethod);
    reporter.testSetStarting(report);
    try {
      for (final Method method : clazz.getMethods()) {
        if (method.getParameterTypes().length == 0
            && requestedTestMethod.equals(method.getName())) {
          Request.method(clazz, method.getName()).getRunner().run(listeners);
        }
      }
    } catch (Throwable e) {
      reporter.testError(
          SimpleReportEntry.withException(
              report.getSourceName(),
              report.getName(),
              new PojoStackTraceWriter(report.getSourceName(), report.getName(), e)));
    } finally {
      reporter.testSetCompleted(report);
    }
    listeners.fireTestRunFinished(result);
    JUnit4RunListener.rethrowAnyTestMechanismFailures(result);

    closeRunNotifier(jUnit4TestSetReporter, customRunListeners);
    return reporterFactory.close();
  }