Example #1
0
  /**
   * @param frameworkMethod
   * @param notifier
   */
  @Override
  protected void runChild(FrameworkMethod frameworkMethod, RunNotifier notifier) {
    try {

      beforeRunChild();
      try {
        // This will execute the createTest method below, the activeContainer handling relies on
        // this.
        System.out.println(
            "START running test "
                + frameworkMethod.getName()
                + " for thread "
                + Thread.currentThread().toString());
        super.runChild(frameworkMethod, notifier);
        System.out.println(
            "END running test "
                + frameworkMethod.getName()
                + " for thread "
                + Thread.currentThread().toString());
      } finally {
        afterRunChild();
      }
    } catch (Throwable e) {
      e.printStackTrace();
      Description description = describeChild(frameworkMethod);
      notifier.fireTestFailure(new Failure(description, e));
      notifier.fireTestFinished(description);
    }
  }
 private Result run(Runner runner) throws InitializationError {
   RunNotifier notifier = new RunNotifier();
   Result result = new Result();
   notifier.addListener(result.createListener());
   runner.run(notifier);
   return result;
 }
Example #3
0
  @Override
  protected void runChild(Interaction interaction, RunNotifier notifier) {
    final Description description = describeChild(interaction);
    notifier.fireTestStarted(description);

    if (interaction.providerState().isDefined()) {
      final Optional<FrameworkMethod> initializationMethod =
          findProvderStateInitializationMethod(interaction.providerState().get());
      if (initializationMethod.isPresent()) {
        try {
          invokeMethod(initializationMethod.get());
          testPact(interaction);
          notifier.fireTestFinished(description);
          return;
        } catch (Exception ex) {
          notifier.fireTestFailure(new Failure(description, ex));
          return;
        }
      } else {
        notifier.fireTestIgnored(description);
        return;
      }
    }
    notifier.fireTestIgnored(description);
  }
Example #4
0
  @Override
  protected void runChild(TestCase testCase, RunNotifier notifier) {
    notifier.fireTestStarted(testCase.name);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
      PolyglotEngine vm =
          PolyglotEngine.newBuilder()
              .setIn(
                  new ByteArrayInputStream(repeat(testCase.testInput, repeats).getBytes("UTF-8")))
              .setOut(out)
              .build();

      String script = readAllLines(testCase.path);

      PrintWriter printer = new PrintWriter(out);
      SLLanguage.run(vm, testCase.path, null, printer, repeats, builtins);
      printer.flush();

      String actualOutput = new String(out.toByteArray());
      Assert.assertEquals(script, repeat(testCase.expectedOutput, repeats), actualOutput);
    } catch (Throwable ex) {
      notifier.fireTestFailure(
          new Failure(
              testCase.name, new IllegalStateException("Cannot run " + testCase.sourceName, ex)));
    } finally {
      notifier.fireTestFinished(testCase.name);
    }
  }
  void runTestMethod(Statement methodInvoker, RunNotifier notifier) {
    Description methodDescription = describeMethod();
    Description methodWithParams = findChildForParams(methodInvoker, methodDescription);

    notifier.fireTestStarted(methodWithParams);
    runMethodInvoker(notifier, methodDescription, methodInvoker, methodWithParams);
    notifier.fireTestFinished(methodWithParams);
  }
 private void closeRunNotifier(
     org.junit.runner.notification.RunListener main,
     List<org.junit.runner.notification.RunListener> others) {
   RunNotifier fNotifier = new RunNotifier();
   fNotifier.removeListener(main);
   for (org.junit.runner.notification.RunListener listener : others) {
     fNotifier.removeListener(listener);
   }
 }
Example #7
0
 protected void runFullSuite(final RunNotifier notifier) {
   JUnitHelper helper = createJUnitHelper(notifier);
   try {
     helper.assertSuitePasses(suiteName, suiteFilter, excludeSuiteFilter);
   } catch (AssertionFailedError e) {
     notifier.fireTestFailure(new Failure(Description.createSuiteDescription(suiteClass), e));
   } catch (Exception e) {
     notifier.fireTestFailure(new Failure(Description.createSuiteDescription(suiteClass), e));
   }
 }
 @Override
 protected void startup(RemoteRunNotifier remote) throws Throwable {
   try {
     RunNotifier notifier = new RunNotifier();
     notifier.addListener(new RemoteRunListener(remote));
     new RemoteTestRunner(this, remote, Class.forName(className)).run(notifier);
   } catch (Throwable failure) {
     runner = failure;
     throw failure;
   }
 }
Example #9
0
 @Override
 protected void runChild(String test, RunNotifier notifier) {
   JUnitHelper helper = createJUnitHelper(notifier);
   try {
     helper.assertTestPasses(test);
   } catch (AssertionFailedError e) {
     notifier.fireTestFailure(new Failure(Description.createSuiteDescription(suiteClass), e));
   } catch (Exception e) {
     notifier.fireTestFailure(new Failure(Description.createSuiteDescription(suiteClass), e));
   }
 }
 @Override
 public void run(RunNotifier notifier) {
   RunListener failureSpy = new ScreenshotCaptureListener();
   notifier.removeListener(failureSpy);
   notifier.addListener(failureSpy);
   try {
     super.run(notifier);
   } finally {
     notifier.removeListener(failureSpy);
   }
 }
  @Override
  protected void runChild(FrameworkMethod method, RunNotifier notifier) {
    Description description = describeChild(method);
    if (method.getAnnotation(Ignore.class) != null) {
      notifier.fireTestIgnored(description);
      return;
    }

    String methodName = method.getName();
    String allowedMethodName = methodNames.get(description);
    if (methodName != null && !methodName.equals(allowedMethodName)) {
      //			notifier.fireTestIgnored(description);
      return;
    }

    try {
      notifier.fireTestStarted(description);
      HttpURLConnection connection = getUrl(methodName, "POST");
      handleError(connection);

      String enc = connection.getContentEncoding();
      if (enc == null) {
        enc = "ISO-8859-1";
      }
      InputStream is = connection.getInputStream();
      BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(enc)));
      String line = null;
      while ((line = reader.readLine()) != null) {
        if (line.startsWith("E")) {
          System.err.println(line.substring(1).trim());
        } else if (line.startsWith("O")) {
          System.out.println(line.substring(1).trim());
        } else if (line.startsWith("RSUCCESS")) {
          break;
        } else if (line.startsWith("RERROR")) {
          StringBuilder error = new StringBuilder(line.substring(6));
          while ((line = reader.readLine()) != null) {
            error.append(line).append("\n");
          }
          throw new AssertionFailedError(error.toString());
        } else {
          log.error("Protocol error in response: {}", line);
        }
      }
      is.close();
      connection.disconnect();
    } catch (Throwable e) {
      e.printStackTrace();
      notifier.fireTestFailure(new Failure(description, e));
    } finally {
      notifier.fireTestFinished(description);
    }
  }
 private RunNotifier getRunNotifier(
     org.junit.runner.notification.RunListener main,
     Result result,
     List<org.junit.runner.notification.RunListener> others) {
   RunNotifier fNotifier = new RunNotifier();
   fNotifier.addListener(main);
   fNotifier.addListener(result.createListener());
   for (org.junit.runner.notification.RunListener listener : others) {
     fNotifier.addListener(listener);
   }
   return fNotifier;
 }
Example #13
0
 /** Do not use. Testing purposes only. */
 public Result run(Runner runner) {
   Result result = new Result();
   RunListener listener = result.createListener();
   fNotifier.addFirstListener(listener);
   try {
     fNotifier.fireTestRunStarted(runner.getDescription());
     runner.run(fNotifier);
     fNotifier.fireTestRunFinished(result);
   } finally {
     removeListener(listener);
   }
   return result;
 }
 protected void invokeTestMethod(JUnit4TestMethod method, RunNotifier notifier) {
   Description description = methodDescription(method);
   Object test;
   try {
     test = createTest();
   } catch (InvocationTargetException e) {
     notifier.testAborted(description, e.getCause());
     return;
   } catch (Exception e) {
     notifier.testAborted(description, e);
     return;
   }
   new JUnit4MethodRoadie(test, method, notifier, description).run();
 }
 @Override
 public void testStarted(WikiTestPage test) {
   firstFailure = null;
   if (test.isTestPage()) {
     notifier.fireTestStarted(descriptionFor(test));
   }
 }
  /** {@inheritDoc} */
  private void notifyTestFinished(final Description junitDescription) {
    if (junitRunNotifier != null && junitDescription != null) {
      log.debug(junitDescription.getDisplayName() + " notifyTestFinished");

      junitRunNotifier.fireTestFinished(junitDescription);
    }
  }
  @Override
  public void fireTestRunFinished(Result result) {
    super.fireTestRunFinished(
        result); // To change body of overridden methods use File | Settings | File Templates.

    retryAwareRunNotifier.fireTestRunFinished(result);
  }
 protected void notifyOfTestSystemException(String testSystemName, Throwable cause) {
   if (cause != null) {
     Exception e =
         new Exception("Exception while executing tests using: " + testSystemName, cause);
     notifier.fireTestFailure(new Failure(Description.createSuiteDescription(mainClass), e));
   }
 }
 public void afterScenario() {
   notifier.fireTestFinished(currentScenario);
   if (scenarioDescriptions.hasNext()) {
     currentScenario = scenarioDescriptions.next();
     finishedDescriptions.clear();
   }
 }
 @Override
 protected void runChild(FrameworkMethod method, RunNotifier notifier) {
   if (canPersist && executeDbTests) {
     super.runChild(method, notifier);
   } else {
     notifier.fireTestIgnored(describeChild(method));
   }
 }
Example #21
0
 @Override
 public void evaluate() throws Throwable {
   Error error = error();
   notifier.addListener(listener);
   try {
     log.debug(displayName(description) + " STARTED");
     for (int retry = 1; retry <= retryCount(); retry++) {
       gotFailure = false;
       onEnter(retry);
       try {
         log.debug(displayName(description) + " retry " + retry);
         base.evaluate();
       } catch (AssumptionViolatedException cause) {
         Throwable t = new Throwable("On retry " + retry).initCause(cause);
         error.addSuppressed(t);
         notifier.fireTestAssumptionFailed(new Failure(description, t));
       } catch (Throwable cause) {
         // Repeat annotation is on method (else the Throwable is not raised up to here)
         Throwable t = new Throwable("On retry " + retry).initCause(cause);
         error.addSuppressed(t);
         if (returnOnFailure()) {
           notifier.fireTestFailure(new Failure(description, t));
         } else {
           gotFailure = true;
           log.debug(displayName(description) + " FAILURE SWALLOW");
           log.trace(t, t);
         }
       } finally {
         onLeave();
       }
       if (gotFailure && returnOnFailure()) {
         log.debug(displayName(description) + " returnOnFailure");
         return;
       }
       if (!gotFailure && returnOnSuccess()) {
         log.debug(displayName(description) + " returnOnSuccess");
         return;
       }
     }
   } finally {
     log.debug(displayName(description) + " FINISHED");
     notifier.removeListener(listener);
   }
   log.trace("throw " + error);
   throw error;
 }
  /** {@inheritDoc} */
  private void notifyTestFailed(final Description junitDescription, final Throwable cause) {
    if (junitRunNotifier != null && junitDescription != null) {
      log.debug(junitDescription.getDisplayName() + " notify running TestFailed");

      log.debug(junitDescription.getDisplayName() + " notify TestFailed");
      junitRunNotifier.fireTestFailure(new Failure(junitDescription, cause));
    }
  }
  @Override
  public void fireTestAssumptionFailed(Failure failure) {
    log.debug("Test assumption failed: " + failure);
    lastAssumptionFailure = failure;
    testAssumptionFailed = true;

    retryAwareRunNotifier.fireTestAssumptionFailed(failure);
  }
  @Override
  public void fireTestFinished(Description description) {
    testStartAlreadyFired = false;
    log.debug("Test finished: " + description);
    lastDescription = description;

    retryAwareRunNotifier.fireTestFinished(description);
  }
Example #25
0
 @Override
 public void run(RunNotifier notifier) {
   Result result = new Result();
   notifier.addFirstListener(result.createListener());
   JUnit5RunnerListener listener = new JUnit5RunnerListener(this.testTree, notifier, result);
   this.launcher.registerTestExecutionListeners(listener);
   this.launcher.execute(this.specification);
 }
  @Override
  public void run(RunNotifier notifier) {
    filteredTests.foreachDoEffect(
        p -> {
          Description desc = p._3();
          notifier.fireTestStarted(desc);
          CheckResult result = checkProperty(p._1(), p._2());

          try {
            CheckResult.summaryEx.showS(result);
          } catch (Throwable t) {
            notifier.fireTestFailure(new Failure(desc, t));
          }

          notifier.fireTestFinished(desc);
        });
  }
  @Override
  public void run(RunNotifier notifier) {
    if (shouldInitMocks) {
      // Allow Mockito to do its verification
      notifier.addListener(new FrameworkUsageValidator(notifier));
    }

    super.run(notifier);
  }
  @Override
  public void fireTestFailure(Failure failure) {
    log.debug("Test failed: " + failure);
    testStartAlreadyFired = false;
    testFailed = true;
    lastFailure = failure;

    retryAwareRunNotifier.fireTestFailure(failure);
  }
 @Override
 public void fireTestStarted(Description description) throws StoppedByUserException {
   int progress = ++this.progress;
   if (progress > total) {
     total = progress;
   }
   console.indicateProgress(progress, total);
   super.fireTestStarted(description);
 }
  // 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();
  }