author | vrany |
Sat, 20 Aug 2011 18:36:33 +0200 | |
changeset 405 | 297b1ec0b153 |
parent 347 | 1f72b6bb67a4 |
child 418 | bc5e6e66a5ee |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
Object subclass:#TestResult |
|
347 | 4 |
instanceVariableNames:'name timestamp failures errors passed outcome' |
5 |
classVariableNames:'DefaultClass' |
|
104 | 6 |
poolDictionaries:'' |
7 |
category:'SUnit-Base' |
|
8 |
! |
|
9 |
||
222 | 10 |
TestResult comment:'' |
0 | 11 |
! |
12 |
||
336 | 13 |
!TestResult class methodsFor:'documentation'! |
14 |
||
15 |
documentation |
|
16 |
" |
|
17 |
runInfoPerTest: |
|
18 |
will keep additional info for a testCase run: |
|
19 |
startTime, endTime, backtrace (if fail or error) and collectedStdout |
|
20 |
" |
|
21 |
! ! |
|
14 | 22 |
|
222 | 23 |
!TestResult class methodsFor:'instance creation'! |
24 |
||
25 |
new |
|
405 | 26 |
|
27 |
self sunitName == #TestCase ifTrue:[ |
|
28 |
^ self defaultResultClass basicNew initialize. |
|
29 |
] ifFalse:[ |
|
30 |
^ self basicNew initialize |
|
31 |
]. |
|
347 | 32 |
|
405 | 33 |
" |
34 |
TestResult new. |
|
35 |
TestResultForRunWithDebug new. |
|
36 |
" |
|
37 |
||
38 |
"Modified (comment): / 20-08-2011 / 17:34:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
347 | 39 |
! ! |
40 |
||
41 |
!TestResult class methodsFor:'accessing'! |
|
42 |
||
43 |
defaultResultClass |
|
44 |
DefaultClass notNil ifTrue:[^DefaultClass]. |
|
45 |
||
46 |
((Smalltalk respondsTo: #isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifTrue:[ |
|
47 |
DefaultClass := TestResultStX. |
|
48 |
^DefaultClass |
|
49 |
]. |
|
50 |
"Add more dialects here, if you want..." |
|
51 |
||
52 |
"Default" |
|
53 |
DefaultClass := self. |
|
54 |
||
55 |
"Created: / 16-08-2011 / 15:02:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
222 | 56 |
! ! |
57 |
||
68 | 58 |
!TestResult class methodsFor:'exceptions'! |
0 | 59 |
|
60 |
error |
|
104 | 61 |
^self exError |
0 | 62 |
! |
63 |
||
64 |
exError |
|
104 | 65 |
^SUnitNameResolver errorObject |
0 | 66 |
! |
67 |
||
68 |
failure |
|
104 | 69 |
^TestFailure |
70 |
! |
|
0 | 71 |
|
104 | 72 |
resumableFailure |
73 |
^ResumableTestFailure |
|
0 | 74 |
! |
75 |
||
222 | 76 |
signalErrorWith: aString |
77 |
self error sunitSignalWith: aString |
|
78 |
! |
|
0 | 79 |
|
222 | 80 |
signalFailureWith: aString |
81 |
self failure sunitSignalWith: aString |
|
0 | 82 |
! ! |
83 |
||
68 | 84 |
!TestResult methodsFor:'accessing'! |
0 | 85 |
|
86 |
defects |
|
104 | 87 |
^OrderedCollection new |
88 |
addAll: self errors; |
|
89 |
addAll: self failures; yourself |
|
0 | 90 |
! |
91 |
||
92 |
errorCount |
|
104 | 93 |
|
347 | 94 |
^self errorOutcomes size |
95 |
||
96 |
"Modified: / 16-08-2011 / 15:58:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
97 |
! |
|
98 |
||
99 |
errorOutcomes |
|
100 |
||
101 |
errors isNil ifTrue: [errors := OrderedCollection new]. |
|
102 |
^errors |
|
103 |
||
104 |
"Created: / 16-08-2011 / 15:55:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
105 |
! |
0 | 106 |
|
107 |
errors |
|
347 | 108 |
|
109 |
errors isNil ifTrue: [^#()]. |
|
110 |
^errors collect:[:outcome|outcome testCase] |
|
111 |
||
112 |
"Modified: / 16-08-2011 / 15:54:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
113 |
! |
0 | 114 |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
115 |
exceptions |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
116 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
117 |
"Returns a set of exceptions to be handled. Bu default, |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
118 |
failure and generic error is handled. This method may |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
119 |
be overriden by custom TestResult subclasses to add more. |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
120 |
For example, a 'self halt' is not handled by default |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
121 |
exceptions set" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
122 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
123 |
^self class failure , self class error |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
124 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
125 |
"Created: / 03-08-2011 / 14:11:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
126 |
! |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
127 |
|
0 | 128 |
failureCount |
129 |
||
347 | 130 |
^self failureOutcomes size |
131 |
||
132 |
"Modified: / 16-08-2011 / 15:58:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
133 |
! |
|
134 |
||
135 |
failureOutcomes |
|
136 |
||
137 |
failures isNil ifTrue: [failures := Set new]. |
|
138 |
^failures |
|
139 |
||
140 |
"Created: / 16-08-2011 / 15:56:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
0 | 141 |
! |
142 |
||
143 |
failures |
|
347 | 144 |
"We use a Set, not an OrderedCollection as #errors and #passed do, because a resumable test failure in a loop can raise many failures against the same test. In current Sunit UIs, this could result in bizarre test count reporting (-27 tests run, and suchlike). This will be reviewed." |
222 | 145 |
|
347 | 146 |
failures isNil ifTrue: [^#()]. |
147 |
^failures collect:[:outcome|outcome testCase] |
|
148 |
||
149 |
"Modified: / 16-08-2011 / 15:54:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
222 | 150 |
! |
151 |
||
152 |
name |
|
153 |
^ name |
|
154 |
! |
|
155 |
||
156 |
name:aString |
|
157 |
name := aString. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
158 |
! |
0 | 159 |
|
53 | 160 |
passed |
347 | 161 |
passed isNil ifTrue: [^#()]. |
162 |
^passed collect:[:outcome|outcome testCase] |
|
163 |
||
164 |
"Modified: / 16-08-2011 / 15:54:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
53 | 165 |
! |
166 |
||
167 |
passedCount |
|
168 |
||
347 | 169 |
^self passedOutcomes size |
170 |
||
171 |
"Modified: / 16-08-2011 / 15:58:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
172 |
! |
|
173 |
||
174 |
passedOutcomes |
|
175 |
||
176 |
passed isNil ifTrue: [passed := OrderedCollection new]. |
|
177 |
^passed |
|
178 |
||
179 |
"Created: / 16-08-2011 / 15:56:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
53 | 180 |
! |
181 |
||
0 | 182 |
runCount |
53 | 183 |
|
104 | 184 |
^self passedCount + self failureCount + self errorCount |
53 | 185 |
! |
186 |
||
347 | 187 |
testOutcomes |
188 |
||
189 |
^(OrderedCollection new: self runCount) |
|
190 |
addAll: self passedOutcomes; |
|
191 |
addAll: self errorOutcomes; |
|
192 |
addAll: self failureOutcomes; |
|
193 |
yourself |
|
194 |
||
195 |
"Created: / 16-08-2011 / 16:42:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
196 |
! |
|
197 |
||
53 | 198 |
tests |
104 | 199 |
|
200 |
^(OrderedCollection new: self runCount) |
|
201 |
addAll: self passed; |
|
202 |
addAll: self errors; |
|
203 |
addAll: self failures; |
|
204 |
yourself |
|
222 | 205 |
! |
206 |
||
207 |
timestamp |
|
208 |
^ timestamp |
|
270 | 209 |
! |
210 |
||
211 |
timestamp:something |
|
212 |
timestamp := something. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
213 |
! ! |
0 | 214 |
|
222 | 215 |
!TestResult methodsFor:'adding'! |
216 |
||
347 | 217 |
addError:testcase detail:detail |
218 |
"Called when a test outcome is error. testCase |
|
219 |
is the errorneous testcase, detail is platform |
|
220 |
specific object describing the error. Actually, |
|
221 |
on all platforms exept GemStone, detail is an instance |
|
222 |
of an exception that caused the error" |
|
223 |
"JV2011-08-03: TODO: Validate the comment above with GS, |
|
224 |
possibly change name to 'exception'" |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
225 |
|
347 | 226 |
testcase class rememberErrorTest:testcase selector. |
227 |
outcome result: #error. |
|
228 |
^ self errorOutcomes add:outcome. |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
229 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
230 |
"Created: / 03-08-2011 / 13:50:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
318
96ce5904bba6
added: #rememberException:detail:
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
231 |
"Modified: / 06-08-2011 / 09:46:41 / cg" |
347 | 232 |
"Modified: / 16-08-2011 / 17:36:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
222 | 233 |
! |
234 |
||
347 | 235 |
addFailure:testcase detail:detail |
236 |
"Called when a test fails. testCase is the failed |
|
237 |
testcase, detail is platform specific object describing |
|
238 |
the failure. Actually, on all platforms exept GemStone, |
|
239 |
detail is an instance of an exception that caused the failure" |
|
240 |
"JV2011-08-03: TODO: Validate the comment above with GS, |
|
241 |
possibly change name to 'exception'" |
|
242 |
||
243 |
testcase class rememberFailedTest:testcase selector. |
|
244 |
"Special handling here, because failures can be resumable" |
|
245 |
self failureOutcomes do:[:outcome | |
|
246 |
outcome testCase = testcase ifTrue:[ |
|
247 |
^ self |
|
248 |
]. |
|
249 |
]. |
|
250 |
outcome result: #fail. |
|
251 |
^ self failureOutcomes add: outcome |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
252 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
253 |
"Created: / 03-08-2011 / 13:53:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
318
96ce5904bba6
added: #rememberException:detail:
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
254 |
"Modified: / 06-08-2011 / 09:55:17 / cg" |
347 | 255 |
"Modified: / 16-08-2011 / 17:37:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
318
96ce5904bba6
added: #rememberException:detail:
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
256 |
! |
96ce5904bba6
added: #rememberException:detail:
Claus Gittinger <cg@exept.de>
parents:
316
diff
changeset
|
257 |
|
347 | 258 |
addPass:testcase |
259 |
testcase class rememberPassedTest:testcase selector. |
|
260 |
outcome result: #pass. |
|
261 |
^ self passedOutcomes add: outcome |
|
325
76240d956e7d
changed: #rememberExceptionIn:detail:
Claus Gittinger <cg@exept.de>
parents:
323
diff
changeset
|
262 |
|
347 | 263 |
"Modified: / 16-08-2011 / 17:16:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
222 | 264 |
! ! |
265 |
||
266 |
!TestResult methodsFor:'deprecated'! |
|
267 |
||
268 |
correctCount |
|
269 |
"deprecated - use #passedCount" |
|
270 |
||
271 |
^self passedCount |
|
272 |
! ! |
|
273 |
||
274 |
!TestResult methodsFor:'initialize-release'! |
|
0 | 275 |
|
276 |
initialize |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
277 |
! ! |
0 | 278 |
|
347 | 279 |
!TestResult methodsFor:'outcome'! |
280 |
||
281 |
createOutcome |
|
282 |
||
283 |
^TestCaseOutcome new. |
|
0 | 284 |
|
347 | 285 |
"Created: / 16-08-2011 / 17:14:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
286 |
! |
|
297
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
287 |
|
347 | 288 |
rememberEndTime |
289 |
||
290 |
^nil |
|
292 | 291 |
|
347 | 292 |
"Created: / 16-08-2011 / 17:31:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
293 |
! |
|
294 |
||
295 |
rememberException:detail |
|
296 |
||
297 |
"Created: / 16-08-2011 / 17:35:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
298 |
! |
|
292 | 299 |
|
347 | 300 |
rememberStartTime |
301 |
||
302 |
^nil |
|
292 | 303 |
|
347 | 304 |
"Created: / 16-08-2011 / 17:31:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
305 |
! ! |
|
306 |
||
307 |
!TestResult methodsFor:'printing'! |
|
292 | 308 |
|
0 | 309 |
printOn: aStream |
104 | 310 |
|
311 |
aStream |
|
312 |
nextPutAll: self runCount printString; |
|
313 |
nextPutAll: ' run, '; |
|
314 |
nextPutAll: self correctCount printString; |
|
315 |
nextPutAll: ' passed, '; |
|
316 |
nextPutAll: self failureCount printString; |
|
317 |
nextPutAll: ' failed, '; |
|
318 |
nextPutAll: self errorCount printString; |
|
319 |
nextPutAll: ' error'. |
|
320 |
||
321 |
self errorCount ~= 1 |
|
322 |
ifTrue: [aStream nextPut: $s] |
|
0 | 323 |
! ! |
324 |
||
68 | 325 |
!TestResult methodsFor:'running'! |
0 | 326 |
|
303 | 327 |
performCase:aTestCase |
328 |
"Actually performs the case. The TestCase>>runCase itself calls |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
329 |
a setUp/tearDown methods. The possible error/failure is handled |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
330 |
in TestResult>>runCase:. This method is meant to be overriden by |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
331 |
custom TestResult subclasses." |
303 | 332 |
|
300
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
333 |
aTestCase runCase. |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
334 |
|
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
335 |
"Modified: / 02-08-2011 / 18:10:09 / cg" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
336 |
"Created: / 03-08-2011 / 14:02:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
337 |
! |
570aed392231
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
297
diff
changeset
|
338 |
|
303 | 339 |
runCase:aTestCase |
316 | 340 |
"run a testcase, catching exceptions" |
341 |
||
303 | 342 |
[ |
347 | 343 |
outcome := self createOutcome. |
344 |
outcome testCase: aTestCase. |
|
345 |
self rememberStartTime. |
|
303 | 346 |
self performCase:aTestCase. |
347 | 347 |
self rememberEndTime. |
348 |
self addPass:aTestCase. |
|
349 |
outcome := nil. |
|
350 |
] sunitOn:self exceptions do: [:ex | |
|
351 |
self rememberEndTime. |
|
352 |
self rememberException: ex. |
|
303 | 353 |
ex sunitAnnounce:aTestCase toResult:self |
354 |
]. |
|
292 | 355 |
|
316 | 356 |
"Modified: / 06-08-2011 / 09:32:32 / cg" |
347 | 357 |
"Modified: / 16-08-2011 / 17:35:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 358 |
! ! |
359 |
||
68 | 360 |
!TestResult methodsFor:'testing'! |
0 | 361 |
|
53 | 362 |
hasErrors |
363 |
||
104 | 364 |
^self errors size > 0 |
53 | 365 |
! |
366 |
||
367 |
hasFailures |
|
368 |
||
104 | 369 |
^self failures size > 0 |
53 | 370 |
! |
371 |
||
0 | 372 |
hasPassed |
104 | 373 |
|
374 |
^self hasErrors not and: [self hasFailures not] |
|
53 | 375 |
! |
376 |
||
377 |
isError: aTestCase |
|
378 |
||
104 | 379 |
^self errors includes: aTestCase |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
380 |
! |
0 | 381 |
|
382 |
isFailure: aTestCase |
|
104 | 383 |
^self failures includes: aTestCase |
53 | 384 |
! |
385 |
||
386 |
isPassed: aTestCase |
|
387 |
||
104 | 388 |
^self passed includes: aTestCase |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
389 |
! ! |
0 | 390 |
|
14 | 391 |
!TestResult class methodsFor:'documentation'! |
392 |
||
393 |
version |
|
405 | 394 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResult.st,v 1.34 2011-08-20 16:36:33 vrany Exp $' |
297
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
395 |
! |
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
396 |
|
87eb8f911bcf
changed: #exceptionInfoStringFor:in:
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
397 |
version_CVS |
405 | 398 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResult.st,v 1.34 2011-08-20 16:36:33 vrany Exp $' |
222 | 399 |
! |
400 |
||
401 |
version_SVN |
|
402 |
^ '§Id: TestResult.st 205 2010-09-11 15:23:01Z vranyj1 §' |
|
14 | 403 |
! ! |