| Method from org.jboss.ant.taskdefs.XMLJUnitResultFormatter Detail: |
public void addError(Test test,
Throwable t) {
formatError(ERROR, test, t);
}
|
public void addFailure(Test test,
Throwable t) {
failures ++;
formatError(FAILURE, test, t);
}
Interface TestListener for JUnit <= 3.4.
A Test failed. |
public void addFailure(Test test,
AssertionFailedError t) {
addFailure(test, (Throwable) t);
}
Interface TestListener for JUnit > 3.4.
A Test failed. |
public void endTest(Test t) {
errors --;
if( hadError == false )
{
rootElement.removeChild(currentTest);
currentTest = doc.createElement(TESTCASE);
currentTest.setAttribute(ATTR_NAME, t.toString());
rootElement.appendChild(currentTest);
}
long elapsed = System.currentTimeMillis()-lastTestStart;
currentTest.setAttribute(ATTR_TIME, ""+(elapsed/ 1000.0));
}
Interface TestListener.
A Test is finished. |
public void endTestSuite(JUnitTest suite) throws BuildException {
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));
try
{
out = new FileOutputStream(outputFile);
}
catch(IOException e)
{
throw new BuildException("Failed to open result file", e);
}
if (out != null)
{
Writer wri = null;
try
{
wri = new OutputStreamWriter(out, "UTF8");
wri.write("< ?xml version=\"1.0\"? >\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)
{
if (wri != null)
{
try
{
wri.close();
}
catch (IOException e)
{
}
}
}
}
}
}
The whole testsuite ended. |
protected File getOutput() {
String filename = "TEST-" + currentSuite.getName() + ".xml";
String reportsDir = currentSuite.getProperties().getProperty("build.reports");
File destFile = new File(reportsDir, filename );
String absFilename = destFile.getAbsolutePath();
return destFile.getAbsoluteFile();
}
Since we are only given an OuptutStream, we have to figure out the
file location based on the |
public void setOutput(OutputStream out) {
this.out = out;
}
|
public void setSystemError(String out) {
formatOutput(SYSTEM_ERR, out);
}
|
public void setSystemOutput(String out) {
formatOutput(SYSTEM_OUT, out);
}
|
public void startTest(Test t) {
lastTestStart = System.currentTimeMillis();
currentTest = doc.createElement(TESTCASE);
currentTest.setAttribute(ATTR_NAME, t.toString());
currentTest.setAttribute(ATTR_TIME, ""+(timeout / 1000.0));
rootElement.appendChild(currentTest);
runs ++;
errors ++;
hadError = false;
// Mark this test as a timeout and write the result file
internalFormatError(ERROR, t, new InternalError("Test timeout"));
currentSuite.setCounts(runs, failures, errors);
long elapsed = lastTestStart - startTime + timeout;
currentSuite.setRunTime(elapsed);
endTestSuite(currentSuite);
}
Interface TestListener.
A new Test is started. |
public void startTestSuite(JUnitTest suite) {
doc = getDocumentBuilder().newDocument();
rootElement = doc.createElement(TESTSUITE);
rootElement.setAttribute(ATTR_NAME, suite.getName());
// 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);
}
}
this.startTime = System.currentTimeMillis();
this.currentSuite = suite;
this.outputFile = this.getOutput();
String junitTimeout = currentSuite.getProperties().getProperty("junit.timeout");
this.timeout = Integer.parseInt(junitTimeout);
}
The whole testsuite started. |