Esempio n. 1
0
 private TestsToRun scanClasspath() {
   TestsToRun scannedClasses =
       parameters
           .getScanResult()
           .applyFilter(new TestPlanScannerFilter(launcher), parameters.getTestClassLoader());
   return parameters.getRunOrderCalculator().orderTestClasses(scannedClasses);
 }
 @Override
 public Iterable<Class<?>> getSuites() {
   return Arrays.asList(
       providerParameters
           .getScanResult()
           .applyFilter(
               clazz ->
                   Arrays.stream(clazz.getAnnotations())
                       .anyMatch(annotation -> Test.class.equals(annotation.annotationType())),
               providerParameters.getTestClassLoader())
           .getLocatedClasses());
 }
 public IsolatedJUnitProvider(ProviderParameters booterParameters) {
   this.providerParameters = booterParameters;
   this.testClassLoader = booterParameters.getTestClassLoader();
   this.scanResult = booterParameters.getScanResult();
   this.runOrderCalculator = booterParameters.getRunOrderCalculator();
   String mode = providerParameters.getProviderProperties().getProperty("compatMode");
   if (!"junit4".equals(mode) && !"junit3".equals(mode)) mode = "junit4";
   this.isJunit4 = "junit4".equals(mode);
   if (isJunit4) {
     junit4TestChecker = new JUnit4TestChecker(testClassLoader);
   } else {
     jUnit3TestChecker = new JUnit3TestChecker(testClassLoader);
     this.v3testChecker = new PojoAndJUnit3Checker(jUnit3TestChecker);
   }
   customRunListeners =
       JUnit4RunListenerFactory.createCustomListeners(
           providerParameters.getProviderProperties().getProperty("listener"));
 }
 @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();
 }
Esempio n. 5
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();
  }
 /**
  * Constructs a new Cuppa Surefire Provider.
  *
  * @param parameters The Surefire provider parameters.
  */
 public CuppaSurefireProvider(ProviderParameters parameters) {
   this.providerParameters = parameters;
   Map<String, String> properties = parameters.getProviderProperties();
   tags = new Tags(getTags(properties), getExcludedTags(properties));
 }