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
38 package junitx.ddtunit;
39
40 import junit.framework.TestCase;
41 import junit.framework.TestFailure;
42 import junitx.ddtunit.resources.RunnerMonitor;
43
44
45
46
47
48
49 public class ExecutionResultTest extends TestCase {
50 private static final String LF = System.getProperty("line.separator");
51
52 private DDTTestResult result;
53
54 private String testResource;
55
56 private String classId;
57
58
59
60
61
62
63 public ExecutionResultTest(String name) {
64 super(name);
65 }
66
67
68
69
70
71
72 public void setUp() {
73 result = new DDTTestResult();
74 result.addListener(RunnerMonitor.getInstance());
75 }
76
77
78
79
80
81
82 public void testRunThreeMethodTestsNoProblem() {
83 this.testResource = "ExecutionResultTest";
84 this.classId = "ExecutionResultNoProblem";
85
86 String testMethod = "testThreeTestsNoProblem";
87 DDTExecutionTest test = new DDTExecutionTest(testMethod);
88
89 test.run(result);
90 assertEquals("Wrong number of methods executed", 1, result.runCount());
91 assertEquals("No failures expected", 0, result.failureCount());
92 assertEquals("No errors expected", 0, result.errorCount());
93
94
95 assertEquals("Wrong number of method tests.", 3, result
96 .runMethodTestCount());
97 assertEquals("No failures in method test execution expected.", 0,
98 result.methodTestFailureCount());
99 assertEquals("No errors in method test execution expected.", 0, result
100 .methodTestErrorCount());
101 }
102
103
104
105
106
107
108 public void testRunThreeMethodTestsOneAssertFailedException() {
109 this.testResource = "ExecutionResultTest";
110 this.classId = "ExecutionResultNoProblem";
111
112 String testMethod = "testThreeTestsOneAssertFailed";
113 DDTExecutionTest test = new DDTExecutionTest(testMethod);
114
115 test.run(result);
116 assertEquals("Wrong number of methods executed", 1, result.runCount());
117 assertEquals("No errors expected", 0, result.errorCount());
118 assertEquals("One failures expected", 1, result.failureCount());
119
120
121 String message = ((TestFailure) result.failures().nextElement())
122 .exceptionMessage();
123 String expected = "method testThreeTestsOneAssertFailed - Total: 3, Errors: 0, Failures: 1"
124 + LF
125 + "F-(my-second-testcase) Wrong isEqual assert on (multiline) string [position 0] expected:<my-unexpected-testcase> but was:<my-second-testcase>";
126 assertEquals("Wrong exepction message in JUnit failure", expected,
127 message);
128 assertEquals("Wrong number of method tests.", 3, result
129 .runMethodTestCount());
130 assertEquals("No errors in method test execution expected.", 0, result
131 .methodTestErrorCount());
132 assertEquals("One failures in method test execution expected.", 1,
133 result.methodTestFailureCount());
134 message = ((TestFailure) result.methodTestFailures().next())
135 .exceptionMessage();
136 expected = "Wrong isEqual assert on (multiline) string [position 0] "
137 + "expected:<my-unexpected-testcase> but was:<my-second-testcase>";
138 assertEquals("Wrong exception message of method test failure",
139 expected, message);
140 }
141
142
143
144
145
146
147 public void testRunThreeMethodTestsOneAssertFailedOneException() {
148 this.testResource = "ExecutionResultTest";
149 this.classId = "ExecutionResultNoProblem";
150
151 String testMethod = "testThreeTestsOneAssertFailedOneException";
152 DDTExecutionTest test = new DDTExecutionTest(testMethod);
153
154 test.run(result);
155 assertEquals("Wrong number of methods executed", 1, result.runCount());
156 assertEquals("One errors expected", 1, result.errorCount());
157 assertEquals("One failures expected", 0, result.failureCount());
158 assertEquals("Wrong number of method tests executed", 3, result
159 .runMethodTestCount());
160 assertEquals("One errors expected", 1, result.methodTestErrorCount());
161 assertEquals("One failures expected", 1, result
162 .methodTestFailureCount());
163
164
165 String message = ((TestFailure) result.errors().nextElement())
166 .exceptionMessage();
167 String expected = "method testThreeTestsOneAssertFailedOneException - "
168 + "Total: 3, Errors: 1, Failures: 1"
169 + LF
170 + "E-(my-first-testcase) Throw expected exception"
171 + LF
172 + "F-(my-second-testcase) Wrong isEqual assert on (multiline) "
173 + "string [position 0] expected:<my-unexpected-testcase> but was:"
174 + "<my-second-testcase>";
175 assertEquals("Wrong exception message in JUnit failure", expected,
176 message);
177 assertEquals("One failures in method test execution expected.", 1,
178 result.methodTestFailureCount());
179 message = (result.methodTestFailures().next()).exceptionMessage();
180 expected = "Wrong isEqual assert on (multiline) string [position 0]"
181 + " expected:<my-unexpected-testcase> but was:<my-second-testcase>";
182 assertEquals("Wrong exception message of method test failure",
183 expected, message);
184 }
185
186
187
188
189
190
191
192 private class DDTExecutionTest extends DDTTestCase {
193
194
195
196
197
198 public DDTExecutionTest(String name) {
199 super(name);
200 }
201
202
203
204
205 protected void initContext() {
206 initTestData(testResource, classId);
207 }
208
209
210
211
212
213 public void testThreeTestsNoProblem() {
214 }
215
216
217
218
219
220 public void testThreeTestsOneAssertFailed() {
221 addObjectToAssert("result", getObject("objId"));
222 }
223
224
225
226
227
228 public void testThreeTestsOneAssertFailedOneException() {
229 String value = (String) getObject("objId");
230
231 addObjectToAssert("result", value);
232
233 if ("my-first-testcase".equals(value)) {
234 throw new DDTException("Throw expected exception");
235 }
236 }
237 }
238 }