/**
   * 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);
    }
  }
Beispiel #2
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;
 }
Beispiel #4
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);
    }
  }