@Override
  public void fireTestAssumptionFailed(Failure failure) {
    log.debug("Test assumption failed: " + failure);
    lastAssumptionFailure = failure;
    testAssumptionFailed = true;

    retryAwareRunNotifier.fireTestAssumptionFailed(failure);
  }
Ejemplo n.º 2
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;
 }
  @Override
  public void evaluate() throws Throwable {
    ProcessBuilder builder = new ProcessBuilder();

    builder.command(buildCommand());
    builder.redirectErrorStream(true);
    builder.directory(testCase.getWorkingDirectory());

    System.out.println("Working directory: " + SystemProperty.INSTANCE.getProperty("user.dir"));
    System.out.println("Command: " + builder.command());

    Description parentDescription = runner.getDescription();

    final Process process = builder.start();

    try {
      Scanner scanner = testCase.startTest(process);

      while (scanner.hasNextLine()) {
        String line = scanner.nextLine();

        if (line.startsWith(JUNIT_OUTPUT_DELIMITER)) {
          System.out.println(line);
          String[] tokens = line.split(JUNIT_OUTPUT_DELIMITER_REGEXP);
          String event = tokens[1];

          if ("testRunStarted".equals(event)) {
            notifier.fireTestRunStarted(parentDescription);
          } else if ("testRunFinished".equals(event)) {
            notifier.fireTestRunFinished(result);
          } else if ("testStarted".equals(event)) {
            Description ofTest = findDescription(parentDescription, tokens[2]);
            notifier.fireTestStarted(ofTest);
          } else if ("testFinished".equals(event)) {
            Description ofTest = findDescription(parentDescription, tokens[2]);
            notifier.fireTestFinished(ofTest);
          } else if ("testFailure".equals(event)) {
            List<String> stackTrace =
                tokens.length > 5
                    ? Arrays.asList(tokens).subList(5, tokens.length - 1)
                    : Collections.<String>emptyList();
            Failure failure =
                toFailure(parentDescription, tokens[2], tokens[3], tokens[4], stackTrace);
            notifier.fireTestFailure(failure);
          } else if ("testAssumptionFailure".equals(event)) {
            List<String> stackTrace =
                tokens.length > 5
                    ? Arrays.asList(tokens).subList(5, tokens.length - 1)
                    : Collections.<String>emptyList();
            Failure failure =
                toFailure(parentDescription, tokens[2], tokens[3], tokens[4], stackTrace);
            notifier.fireTestAssumptionFailed(failure);
          } else if ("testIgnored".equals(event)) {
            Description ofTest = findDescription(parentDescription, tokens[2]);
            notifier.fireTestIgnored(ofTest);
          }
        } else {
          System.out.println(line);
        }
      }
    } catch (Throwable t) {
      System.err.println("Failed to execute test");
      t.printStackTrace();

      throw t;
    } finally {
      try {
        testCase.endTest(process);
      } finally {

        Timer timer = new Timer();
        timer.schedule(
            new TimerTask() {

              @Override
              public void run() {
                process.destroy();
              }
            },
            10 * 1000);

        try {
          process.waitFor();
        } catch (InterruptedException e) {
          // ignore
        }

        timer.cancel();
      }
    }
  }
  private void reportTestAsNotApplicableInCurrentTestRun(Method method) {
    Class<?> testClass = method.getDeclaringClass();
    Description testDescription = Description.createTestDescription(testClass, method.getName());

    runNotifier.fireTestAssumptionFailed(new Failure(testDescription, NOT_APPLICABLE));
  }
Ejemplo n.º 5
0
 private void ignoreRequest(RunNotifier notifier, Exception e) {
   notifier.fireTestStarted(getDescription());
   notifier.fireTestAssumptionFailed(new Failure(getDescription(), e));
   notifier.fireTestFinished(getDescription());
 }