private void formatError(String type, Test test, Throwable t) { synchronized (out) { if (test != null) { endTest(test); failed.put(test, Boolean.TRUE); } Object[] args = { JUnitVersionHelper.getTestCaseName(test), type, t.getMessage(), JUnitTestRunner.getFilteredTrace(t), }; MessageFormat form = new MessageFormat("\n{0}: {2}\n{3}\n"); try { out.write(form.format(args).getBytes()); out.flush(); } catch (IOException ioex) { throw new BuildException("Unable to write output", ioex); } // DO NOT CLOSE the out stream!!! } }
/** * Interface TestListener. * * <p>A Test is finished. * @param test the test. */ public void endTest(final Test test) { final String testDescription = createDescription(test); // Fix for bug #5637 - if a junit.extensions.TestSetup is // used and throws an exception during setUp then startTest // would never have been called if (!testStarts.containsKey(testDescription)) { startTest(test); } Element currentTest; if (!failedTests.containsKey(test) && !skippedTests.containsKey(testDescription) && !ignoredTests.containsKey(testDescription)) { currentTest = doc.createElement(TESTCASE); String n = JUnitVersionHelper.getTestCaseName(test); if (n != null && !tag.isEmpty()) n = n + "-" + tag; currentTest.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n); // a TestSuite can contain Tests from multiple classes, // even tests with the same name - disambiguate them. currentTest.setAttribute(ATTR_CLASSNAME, JUnitVersionHelper.getTestCaseClassName(test)); rootElement.appendChild(currentTest); testElements.put(createDescription(test), currentTest); } else { currentTest = testElements.get(testDescription); } final Long l = testStarts.get(createDescription(test)); currentTest.setAttribute(ATTR_TIME, "" + ((System.currentTimeMillis() - l) / ONE_SECOND)); }
public void endTest(Test test) { testData.setEndTime(new Date()); // Write failed tests to the output file if (!Boolean.TRUE.equals(failed.get(test))) { synchronized (wri) { wri.print("Testcase: " + JUnitVersionHelper.getTestCaseName(test)); Long l = testStarts.get(test); double seconds = 0; // can be null if an error occurred in setUp if (l != null) { seconds = (System.currentTimeMillis() - l.longValue()) / 1000.0; } wri.println(" took " + nf.format(seconds) + " sec"); } } // Let updateStatus determine if the test actually passed testData.updateStatus(CMnDbUnitTestData.PASS); // Don't bother saving the debug statements if the test passed if (testData.getStatus() == CMnDbUnitTestData.PASS) { testData.clearMessage(); } // Write the info for the current test to the database try { CMnUnittestTable.getInstance().addTest(conn, suiteId, testData); } catch (Exception ex) { System.err.println("Unable to add unit test information to the database."); ex.printStackTrace(); } }
@Override public void startTest(Test test) { testStarts_.put(test, System.currentTimeMillis()); String methodName = JUnitVersionHelper.getTestCaseName(test); output_.print(methodName); int l = 40-methodName.length(); if (l>=3) { output_.print(SPACES.substring(0, l)); } else { output_.print(" .."); } }
/** * Format an error and print it. * @param type the type of error * @param test the test that failed * @param error the exception that the test threw */ protected void formatError(String type, Test test, Throwable error) { if (test == null) { return; } StringBuilder sb = new StringBuilder(); sb.append(error.getClass().getSimpleName()) .append(": ") .append((error.getMessage() != null) ? error.getMessage() : error.toString()) .append('\n'); String testCaseClassName = JUnitVersionHelper.getTestCaseClassName(test); for (StackTraceElement ste : error.getStackTrace()) { if (ste.getClassName().equals(testCaseClassName)) { sb.append(" at ") .append(ste.getFileName()) .append(':') .append(ste.getLineNumber()) .append(" (") .append(ste.getMethodName()) .append(')'); } } failedTests_.put(test, sb.toString()); }
public void testIgnored(Test test) { formatSkip(test, JUnitVersionHelper.getIgnoreMessage(test)); }
private static String createDescription(final Test test) throws BuildException { if (!tag.isEmpty()) return JUnitVersionHelper.getTestCaseName(test) + "-" + tag +"(" + JUnitVersionHelper.getTestCaseClassName(test) + ")"; return JUnitVersionHelper.getTestCaseName(test) + "(" + JUnitVersionHelper.getTestCaseClassName(test) + ")"; }
public void testIgnored(final Test test) { formatSkip(test, JUnitVersionHelper.getIgnoreMessage(test)); if (test != null) { ignoredTests.put(createDescription(test), test); } }