Skip to content

Commit

Permalink
Fixed stack trace in test report.
Browse files Browse the repository at this point in the history
The report generator has been fixed to show the stack trace from
the test source code.

Ticket #36
  • Loading branch information
edewata committed Dec 5, 2011
1 parent 343a8af commit 8bcaa20
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions pki/base/common/test/com/netscape/test/TestListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;

import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
Expand Down Expand Up @@ -217,15 +216,31 @@ public void recordTestCaseFailure(Failure failure) throws Exception {
testCaseElement.appendChild(failureElement);

Description description = failure.getDescription();
String exceptionName = failure.getException().getClass().getName();
Throwable exception = failure.getException();
String exceptionName = exception.getClass().getName();

failureElement.setAttribute("message", failure.getMessage());
failureElement.setAttribute("type", exceptionName);

Text messageElement = document.createTextNode(
exceptionName + ": " +failure.getMessage() + "\n\tat " +
description.getClassName() + "." + description.getMethodName() + "()"
exceptionName + ": " +failure.getMessage() + "\n"
);

// print stack trace
for (StackTraceElement element : exception.getStackTrace()) {
if (!element.getClassName().equals(description.getClassName())) continue;

String source = "Unknown Source";
if (element.getFileName() != null && element.getLineNumber() >= 0) {
source = element.getFileName() + ":" + element.getLineNumber();
}

messageElement.appendData("\tat " +
element.getClassName() + "." + element.getMethodName() +
"(" + source + ")\n"
);
}

failureElement.appendChild(messageElement);

failureCount++;
Expand Down

0 comments on commit 8bcaa20

Please sign in to comment.