Esempio n. 1
0
  private void invokeSingleClass(Class<?> testClass, RunListener runListener) {
    SimpleReportEntry classEntry = new SimpleReportEntry(getClass().getName(), testClass.getName());
    runListener.testSetStarting(classEntry);

    LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClass(testClass)).build();
    launcher.execute(discoveryRequest);

    runListener.testSetCompleted(classEntry);
  }
  // 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();
  }