Format the test results in XML.
| Method from org.apache.cactus.internal.server.runner.XMLFormatter Detail: |
public void addError(Test theTest,
Throwable theThrowable) {
TestFailure failure = new TestFailure(theTest, theThrowable);
StringBuffer xml = new StringBuffer();
xml.append("< " + ERROR + " " + ATTR_MESSAGE + "=\""
+ xmlEncode(failure.thrownException().getMessage()) + "\" "
+ ATTR_TYPE + "=\""
+ failure.thrownException().getClass().getName() + "\" >");
xml.append(xmlEncode(StringUtil.exceptionToString(
failure.thrownException(), DEFAULT_STACK_FILTER_PATTERNS)));
xml.append("< /" + ERROR + " >");
this.currentTestFailure = xml.toString();
}
Event called by the base test runner when the test fails with an error. |
public void addFailure(Test theTest,
AssertionFailedError theError) {
TestFailure failure = new TestFailure(theTest, theError);
StringBuffer xml = new StringBuffer();
xml.append("< " + FAILURE + " " + ATTR_MESSAGE + "=\""
+ xmlEncode(failure.thrownException().getMessage()) + "\" "
+ ATTR_TYPE + "=\""
+ failure.thrownException().getClass().getName() + "\" >");
xml.append(xmlEncode(StringUtil.exceptionToString(
failure.thrownException(), DEFAULT_STACK_FILTER_PATTERNS)));
xml.append("< /" + FAILURE + " >");
this.currentTestFailure = xml.toString();
}
Event called by the base test runner when the test fails with a failure. |
public void endTest(Test theTest) {
StringBuffer xml = new StringBuffer();
String duration = getDurationAsString(System.currentTimeMillis()
- this.currentTestStartTime);
xml.append("< " + TESTCASE + " " + ATTR_NAME + "=\""
+ JUnitVersionHelper.getTestCaseName(theTest) + "\" "
+ ATTR_TIME + "=\"" + duration + "\" >");
if (this.currentTestFailure != null)
{
xml.append(this.currentTestFailure);
}
xml.append("< /" + TESTCASE + " >");
this.currentTestCaseResults.append(xml.toString());
}
Event called by the base test runner when the test ends. |
public String getEncoding() {
return this.encoding;
}
|
public String getSuiteClassName() {
return this.suiteClassName;
}
|
public String getTotalDurationAsString() {
return getDurationAsString(this.totalDuration);
}
|
public void setEncoding(String theEncoding) {
this.encoding = theEncoding;
}
|
public void setSuiteClassName(String theSuiteClassName) {
this.suiteClassName = theSuiteClassName;
}
Sets the suite class name that was executed. |
public void setTotalDuration(long theDuration) {
this.totalDuration = theDuration;
}
Sets the duration it took to execute all the tests. |
public void setXslFileName(String theXslFileName) {
this.xslFileName = theXslFileName;
}
Sets the XSL stylesheet file name to put in the returned XML string
so that the browser will try to apply it (IE at least, I don't know
about the others). |
public void startTest(Test theTest) {
this.currentTestStartTime = System.currentTimeMillis();
this.currentTestFailure = null;
}
Event called by the base test runner when the test starts. |
public String toXML(TestResult theResult) {
StringBuffer xml = new StringBuffer();
xml.append("< ?xml version=\"1.0\" encoding=\"" + getEncoding()
+ "\"? >");
if (this.xslFileName != null)
{
xml.append("< ?xml-stylesheet type=\"text/xsl\" " + "href=\""
+ this.xslFileName + "\"? >");
}
xml.append("< " + TESTSUITES + " >");
xml.append("< " + TESTSUITE + " " + ATTR_NAME + "=\""
+ getSuiteClassName() + "\" " + ATTR_TESTS + "=\""
+ theResult.runCount() + "\" " + ATTR_FAILURES + "=\""
+ theResult.failureCount() + "\" " + ATTR_ERRORS + "=\""
+ theResult.errorCount() + "\" " + ATTR_TIME + "=\""
+ getTotalDurationAsString() + "\" >");
xml.append(this.currentTestCaseResults.toString());
xml.append("< /" + TESTSUITE + " >");
xml.append("< /" + TESTSUITES + " >");
return xml.toString();
}
Formats the test result as an XML string. |