Esempio n. 1
0
  /** Runs the tests and collects their result in a TestResult. */
  public void run(TestResult result) {
    // it probably make some sense to call result.run(this),
    // but, to avoid the suite being counted we try/catch ourselves
    try {
      setUp();
    } catch (AssertionFailedError e) {
      result.addFailure(this, e);
      return;
    } catch (ThreadDeath e) { // don't catch ThreadDeath by accident
      throw e;
    } catch (Throwable e) {
      result.addError(this, e);
      return;
    }

    for (Enumeration e = tests(); e.hasMoreElements(); ) {
      if (result.shouldStop()) break;
      Test test = (Test) e.nextElement();
      runTest(test, result);
    }

    try {
      tearDown();
    } catch (AssertionFailedError e) {
      result.addFailure(this, e);
      return;
    } catch (ThreadDeath e) { // don't catch ThreadDeath by accident
      throw e;
    } catch (Throwable e) {
      result.addError(this, e);
      return;
    }
  }
Esempio n. 2
0
 @SuppressWarnings("unchecked")
 @Override
 public void run(TestResult result) {
   result.startTest(this);
   ScriptRuntime runtime =
       new ScriptRuntime(script, environment, false, new HashMap<String, Object>());
   runtime.setLabelEvaluator(new EnvironmentLabelEvaluator(label));
   runtime.run();
   // map the exception (if any)
   if (runtime.getException() != null) {
     result.addError(this, runtime.getException());
   }
   // check all the validations that occurred
   List<Validation<?>> validations = (List<Validation<?>>) runtime.getContext().get("$validation");
   for (Validation<?> validation : validations) {
     if (validation.getSeverity() == Severity.ERROR
         || validation.getSeverity() == Severity.CRITICAL) {
       result.addFailure(this, new AssertionFailedError(validation.toString()));
       if (!addAllFailures) {
         break;
       }
     }
   }
   result.endTest(this);
 }
Esempio n. 3
0
  /**
   * Handles test fail.
   *
   * @param result Test result.
   * @param origTest Original JUnit test.
   * @param e Exception thrown from grid.
   */
  private void handleFail(TestResult result, GridJunit3SerializableTest origTest, Throwable e) {
    // Simulate that all tests were run.
    origTest.getTest().run(result);

    // For the tests suite we assume that all tests failed because
    // entire test suite execution failed and there is no way to get
    // broken tests.
    if (origTest.getTest() instanceof GridJunit3TestSuiteProxy) {
      TestSuite suite = (((TestSuite) origTest.getTest()));

      for (int j = 0; j < suite.testCount(); j++) {
        result.addError(suite.testAt(j), e);
      }
    } else if (origTest.getTest() instanceof GridJunit3TestCaseProxy) {
      result.addError(origTest.getTest(), e);
    }
  }
Esempio n. 4
0
 private void addErrorMessage(TestResult testResult, String message) {
   String processedTestsMessage =
       myRunTests <= 0 ? "None of tests was run" : myRunTests + " tests processed";
   try {
     testResult.startTest(this);
     testResult.addError(this, new Throwable(processedTestsMessage + " before: " + message));
     testResult.endTest(this);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 /**
  * Report results as error, failure, or success (ignored), differently if result is null
  *
  * @param description the String description of the result
  * @param isError if true, report as failure
  * @param isFailure if true and not isError, report as failure
  * @param test the Test case
  * @param result the TestResult sink - ignored if null
  * @return 0
  */
 private static int reportResultToJUnit(
     String description, boolean isError, boolean isFailure, Test test, TestResult result) {
   if (null != result) {
     if (isError) {
       result.addError(test, new AssertionFailedError(description));
     } else if (isFailure) {
       result.addFailure(test, new AssertionFailedError(description));
     } // no need to log success
   } else { // have to throw failure
     if (isError) {
       String m = safeTestName(test) + " " + description;
       throw new Error(m);
     } else if (isFailure) {
       //                String m = safeTestName(test) + " " + description;
       throw new AssertionFailedError(description);
     } // no need to log success
   }
   return 0;
 }
Esempio n. 6
0
  private void runNextTest(final TestResult testResult, int totalTests, Class testCaseClass) {
    myRunTests++;
    if (!checkAvaliableMemory(35, testResult)) {
      testResult.stop();
      return;
    }
    if (testResult.errorCount() + testResult.failureCount() > MAX_FAILURE_TEST_COUNT) {
      addErrorMessage(
          testResult,
          "Too many errors. Tests stopped. Total "
              + myRunTests
              + " of "
              + totalTests
              + " tests run");
      testResult.stop();
      return;
    }
    if (myStartTime == 0) {
      boolean ourClassLoader =
          getClass().getClassLoader().getClass().getName().startsWith("com.intellij.");
      if (!ourClassLoader) {
        beforeFirstTest();
      }
    } else {
      if (myInterruptedByOutOfTime) {
        addErrorMessage(
            testResult,
            "Current Test Interrupted: OUT OF TIME! Class = "
                + myLastTestClass
                + " Total "
                + myRunTests
                + " of "
                + totalTests
                + " tests run");
        testResult.stop();
        return;
      }
    }

    log("\nRunning " + testCaseClass.getName());
    final Test test = getTest(testCaseClass);

    if (test == null) return;

    myLastTestClass = null;

    myLastTestClass = testCaseClass.getName();
    myLastTestStartTime = System.currentTimeMillis();
    myLastTestTestMethodCount = test.countTestCases();

    try {
      test.run(testResult);
    } catch (Throwable t) {
      if (t instanceof OutOfMemoryError) {
        if ((ourMode & SAVE_MEMORY_SNAPSHOT) != 0) {
          try {
            mySavingMemorySnapshot = true;
            log("OutOfMemoryError detected. Saving memory snapshot started");
          } finally {
            log("Saving memory snapshot finished");
            mySavingMemorySnapshot = false;
          }
        }
      }
      testResult.addError(test, t);
    }
  }
Esempio n. 7
0
  @Override
  public void run(TestResult result) {
    result.startTest(this);

    try {
      // define request
      Security security = SecurityFactory.getInstance(delegator);
      MockServletContext servletContext = new MockServletContext();
      request.setAttribute("security", security);
      request.setAttribute("servletContext", servletContext);
      request.setAttribute("delegator", delegator);
      request.setAttribute("dispatcher", dispatcher);
      Map<String, Object> serviceResult =
          SimpleMethod.runSimpleService(
              methodLocation,
              methodName,
              dispatcher.getDispatchContext(),
              UtilMisc.toMap(
                  "test",
                  this,
                  "testResult",
                  result,
                  "locale",
                  Locale.getDefault(),
                  "request",
                  request,
                  "response",
                  response));

      // do something with the errorMessage
      String errorMessage = (String) serviceResult.get(ModelService.ERROR_MESSAGE);
      if (UtilValidate.isNotEmpty(errorMessage)) {
        result.addFailure(this, new AssertionFailedError(errorMessage));
      }

      // do something with the errorMessageList
      List<Object> errorMessageList =
          UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_LIST));
      if (UtilValidate.isNotEmpty(errorMessageList)) {
        for (Object message : errorMessageList) {
          result.addFailure(this, new AssertionFailedError(message.toString()));
        }
      }

      // do something with the errorMessageMap
      Map<String, Object> errorMessageMap =
          UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_MAP));
      if (!UtilValidate.isEmpty(errorMessageMap)) {
        for (Map.Entry<String, Object> entry : errorMessageMap.entrySet()) {
          result.addFailure(
              this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue()));
        }
      }

    } catch (MiniLangException e) {
      result.addError(this, e);
    } catch (SecurityConfigurationException e) {
      result.addError(this, e);
    }

    result.endTest(this);
  }