1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 package junitx.ddtunit;
38
39 import junit.framework.AssertionFailedError;
40 import junit.framework.Test;
41 import junit.framework.TestCase;
42 import junit.textui.ResultPrinter;
43
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47
48
49
50
51
52
53
54
55 public class DDTRunMonitor extends ResultPrinter implements DDTTestListener {
56 private static DDTRunMonitor singletonRef;
57
58 private Logger log = LoggerFactory.getLogger(DDTRunMonitor.class);
59
60 private int testRuns = 0;
61
62 private int testErrors = 0;
63
64 private int testFailures = 0;
65
66
67
68
69 private DDTRunMonitor() {
70 super(System.out);
71 }
72
73
74
75
76
77
78 static public DDTRunMonitor getInstance() {
79 if (singletonRef == null) {
80 singletonRef = new DDTRunMonitor();
81 }
82
83 return singletonRef;
84 }
85
86
87
88
89
90
91
92 public void addMethodTestError(Test test, String testName,
93 Throwable throwable) {
94 String method = "";
95
96 if (TestCase.class.isInstance(test)) {
97 method = ((TestCase) test).getName();
98 }
99
100 log.info("[" + test.getClass() + "] Error method " + method + ", test "
101 + testName);
102 log.info("Cause: ", throwable);
103 this.testErrors++;
104 }
105
106
107
108
109
110
111
112 public void addMethodTestFailure(Test test, String testName,
113 AssertionFailedError assertFailed) {
114 String method = "";
115
116 if (TestCase.class.isInstance(test)) {
117 method = ((TestCase) test).getName();
118 }
119
120 log.info("[" + test.getClass() + "] Failure method " + method
121 + ", test " + testName);
122 log.info("Cause: ", assertFailed);
123 this.testFailures++;
124 }
125
126
127
128
129
130
131
132 public void endMethodTest(IDDTTestCase test, String testName) {
133 int testCount = test.countMethodTests();
134 String method = test.getName();
135 log.info("[" + test.getClass() + "] (" + this.testRuns + "/"
136 + testCount + ") method \"" + method + "\", test \"" + testName
137 + "\"");
138 }
139
140
141
142
143
144
145
146 public void startMethodTest(IDDTTestCase test, String testName) {
147 String method = test.getName();
148 int testCount = test.countMethodTests();
149 this.testRuns++;
150 log.debug("[" + test.getClass() + "] Start method " + method + " ("
151 + this.testRuns + " of " + testCount + ") test " + testName);
152 }
153
154
155
156
157
158
159
160 public void addError(Test test, Throwable t) {
161 String method = "";
162
163 if (TestCase.class.isInstance(test)) {
164 method = ((TestCase) test).getName();
165 }
166 log.info("[" + test.getClass() + "] method " + method + " error:", t);
167 }
168
169
170
171
172
173
174
175 public void addFailure(Test test, AssertionFailedError t) {
176 String method = "";
177
178 if (TestCase.class.isInstance(test)) {
179 method = ((TestCase) test).getName();
180 }
181
182 log.info("[" + test.getClass() + "] Add Faiure method " + method, t);
183 }
184
185
186
187
188
189
190 public void endTest(Test test) {
191 String method = "";
192 if (TestCase.class.isInstance(test)) {
193 method = ((TestCase) test).getName();
194 }
195 if (IDDTTestCase.class.isInstance(test)) {
196 int testCount = ((IDDTTestCase) test).countMethodTests();
197 log.info("[" + test.getClass() + "] method \"" + method + "\": "
198 + testRuns + " of " + testCount + " test(s), " + testErrors
199 + " error(s), " + testFailures + " failure(s)");
200 } else {
201 log
202 .info("[" + test.getClass() + "] method \"" + method + "\": "
203 + testErrors + " error(s), " + testFailures
204 + " failure(s)");
205 }
206 }
207
208
209
210
211
212
213 public void startTest(Test test) {
214 String method = "";
215 this.testRuns = 0;
216 this.testErrors = 0;
217 this.testFailures = 0;
218
219 if (TestCase.class.isInstance(test)) {
220 method = ((TestCase) test).getName();
221 }
222 log.debug("[" + test.getClass() + "] Start method \"" + method + "\"");
223 }
224 }