Methods Summary |
---|
public void | addError(junit.framework.Test test, java.lang.Throwable t)Interface TestListener.
An error occurred while running the test.
formatError(ERROR, test, t);
|
public void | addFailure(junit.framework.Test test, java.lang.Throwable t)Interface TestListener for JUnit <= 3.4.
A Test failed.
formatError(FAILURE, test, t);
|
public void | addFailure(junit.framework.Test test, junit.framework.AssertionFailedError t)Interface TestListener for JUnit > 3.4.
A Test failed.
addFailure(test, (Throwable) t);
|
public void | endTest(junit.framework.Test test)Interface TestListener.
A Test is finished.
// 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(test)) {
startTest(test);
}
Element currentTest = null;
if (!failedTests.containsKey(test)) {
currentTest = doc.createElement(TESTCASE);
String n = JUnitVersionHelper.getTestCaseName(test);
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(test, currentTest);
} else {
currentTest = (Element) testElements.get(test);
}
Long l = (Long) testStarts.get(test);
currentTest.setAttribute(ATTR_TIME,
"" + ((System.currentTimeMillis() - l.longValue()) / 1000.0));
|
public void | endTestSuite(JUnitTest suite)The whole testsuite ended.
rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount());
rootElement.setAttribute(ATTR_FAILURES, "" + suite.failureCount());
rootElement.setAttribute(ATTR_ERRORS, "" + suite.errorCount());
rootElement.setAttribute(ATTR_TIME, "" + (suite.getRunTime() / 1000.0));
if (out != null) {
Writer wri = null;
try {
wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8"));
wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
(new DOMElementWriter()).write(rootElement, wri, 0, " ");
wri.flush();
} catch (IOException exc) {
throw new BuildException("Unable to write log file", exc);
} finally {
if (out != System.out && out != System.err) {
FileUtils.close(wri);
}
}
}
|
private void | formatError(java.lang.String type, junit.framework.Test test, java.lang.Throwable t)
if (test != null) {
endTest(test);
failedTests.put(test, test);
}
Element nested = doc.createElement(type);
Element currentTest = null;
if (test != null) {
currentTest = (Element) testElements.get(test);
} else {
currentTest = rootElement;
}
currentTest.appendChild(nested);
String message = t.getMessage();
if (message != null && message.length() > 0) {
nested.setAttribute(ATTR_MESSAGE, t.getMessage());
}
nested.setAttribute(ATTR_TYPE, t.getClass().getName());
String strace = JUnitTestRunner.getFilteredTrace(t);
Text trace = doc.createTextNode(strace);
nested.appendChild(trace);
|
private void | formatOutput(java.lang.String type, java.lang.String output)
Element nested = doc.createElement(type);
rootElement.appendChild(nested);
nested.appendChild(doc.createCDATASection(output));
|
private static javax.xml.parsers.DocumentBuilder | getDocumentBuilder()
try {
return DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (Exception exc) {
throw new ExceptionInInitializerError(exc);
}
|
private java.lang.String | getHostname()get the local hostname
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
return "localhost";
}
|
public void | setOutput(java.io.OutputStream out){@inheritDoc}.
this.out = out;
|
public void | setSystemError(java.lang.String out){@inheritDoc}.
formatOutput(SYSTEM_ERR, out);
|
public void | setSystemOutput(java.lang.String out){@inheritDoc}.
formatOutput(SYSTEM_OUT, out);
|
public void | startTest(junit.framework.Test t)Interface TestListener.
A new Test is started.
testStarts.put(t, new Long(System.currentTimeMillis()));
|
public void | startTestSuite(JUnitTest suite)The whole testsuite started.
doc = getDocumentBuilder().newDocument();
rootElement = doc.createElement(TESTSUITE);
String n = suite.getName();
rootElement.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n);
//add the timestamp
final String timestamp = DateUtils.format(new Date(),
DateUtils.ISO8601_DATETIME_PATTERN);
rootElement.setAttribute(TIMESTAMP, timestamp);
//and the hostname.
rootElement.setAttribute(HOSTNAME, getHostname());
// Output properties
Element propsElement = doc.createElement(PROPERTIES);
rootElement.appendChild(propsElement);
Properties props = suite.getProperties();
if (props != null) {
Enumeration e = props.propertyNames();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
Element propElement = doc.createElement(PROPERTY);
propElement.setAttribute(ATTR_NAME, name);
propElement.setAttribute(ATTR_VALUE, props.getProperty(name));
propsElement.appendChild(propElement);
}
}
|