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(); } }
@Override public void run(final TestResult testResult) { List<Class> classes = myTestCaseLoader.getClasses(); int totalTests = classes.size(); for (final Class aClass : classes) { runNextTest(testResult, totalTests, aClass); if (testResult.shouldStop()) break; } tryGc(10); }
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); } }