01: package org.depunit;
02:
03: import java.util.*;
04: import org.w3c.dom.*;
05:
06: public class TestResult {
07: public static final String STATUS_SUCCESS = "success";
08: public static final String STATUS_NOT_RAN = "not_ran";
09: public static final String STATUS_SKIPPED = "skipped";
10: public static final String STATUS_FAILED = "failed";
11:
12: private String m_status;
13: private TestMethod m_testMethod;
14: private Throwable m_exception; //Stack trace in case of an error condition
15:
16: public TestResult(TestMethod tm) {
17: m_testMethod = tm;
18: m_status = tm.getStatus();
19: }
20:
21: //---------------------------------------------------------------------------
22: public void setStatus(String status) {
23: m_status = status;
24: m_testMethod.setStatus(status);
25: }
26:
27: //---------------------------------------------------------------------------
28: public String getStatus() {
29: return (m_status);
30: }
31:
32: //---------------------------------------------------------------------------
33: public void setException(Throwable t) {
34: m_exception = t;
35: }
36:
37: //---------------------------------------------------------------------------
38: public String toString() {
39: return ("");
40: }
41:
42: //---------------------------------------------------------------------------
43: public void reportStatus(Document doc, Element test) {
44: test.setAttribute("name", "");
45: test.setAttribute("class", m_testMethod.getTestClass()
46: .getFullName());
47: test.setAttribute("method", m_testMethod.getMethodName());
48: test.setAttribute("status", m_status);
49:
50: Element groups = doc.createElement("groups");
51: test.appendChild(groups);
52:
53: //Add to report the parameters that were set
54: if (m_status.equals(STATUS_FAILED)) {
55: Element error = doc.createElement("error");
56: Element message = doc.createElement("message");
57: String msgStr = m_exception.getMessage();
58: if (msgStr != null)
59: message.appendChild(doc.createTextNode(m_exception
60: .getMessage()));
61: error.appendChild(message);
62:
63: Element stack = doc.createElement("stack");
64: error.appendChild(stack);
65:
66: StackTraceElement[] stackTrace = m_exception
67: .getStackTrace();
68: for (StackTraceElement ste : stackTrace) {
69: if (ste.getMethodName().equals("invoke0"))
70: break;
71:
72: Element trace = doc.createElement("trace");
73: trace.setAttribute("className", ste.getClassName());
74: trace.setAttribute("fileName", ste.getFileName());
75: trace.setAttribute("methodName", ste.getMethodName());
76: trace.setAttribute("lineNumber", String.valueOf(ste
77: .getLineNumber()));
78: trace.setAttribute("print", ste.toString());
79:
80: stack.appendChild(trace);
81: }
82:
83: test.appendChild(error);
84: }
85: }
86: }
|