author | Claus Gittinger <cg@exept.de> |
Wed, 03 Sep 2008 10:50:25 +0200 | |
changeset 183 | 657b3b690c83 |
parent 136 | 483eb95e98b7 |
child 222 | 8e6f482297fa |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
Object subclass:#TestResult |
|
104 | 4 |
instanceVariableNames:'failures errors passed' |
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'SUnit-Base' |
|
8 |
! |
|
9 |
||
10 |
TestResult comment:'This is a Collecting Parameter for the running of a bunch of tests. TestResult is an interesting object to subclass or substitute. #runCase: is the external protocol you need to reproduce. Kent has seen TestResults that recorded coverage information and that sent email when they were done.' |
|
0 | 11 |
! |
12 |
||
14 | 13 |
|
68 | 14 |
!TestResult class methodsFor:'exceptions'! |
0 | 15 |
|
16 |
error |
|
104 | 17 |
^self exError |
18 |
||
0 | 19 |
! |
20 |
||
21 |
exError |
|
104 | 22 |
^SUnitNameResolver errorObject |
23 |
||
0 | 24 |
! |
25 |
||
26 |
failure |
|
104 | 27 |
^TestFailure |
28 |
||
29 |
! |
|
0 | 30 |
|
104 | 31 |
resumableFailure |
32 |
^ResumableTestFailure |
|
33 |
||
0 | 34 |
! |
35 |
||
36 |
signalErrorWith: aString |
|
104 | 37 |
|
38 |
"/ self error sunitSignalWith: aString |
|
101 | 39 |
self exError raiseErrorString: aString |
0 | 40 |
! |
41 |
||
42 |
signalFailureWith: aString |
|
104 | 43 |
|
44 |
"/ self failure sunitSignalWith: aString |
|
33 | 45 |
self failure raiseErrorString: aString |
0 | 46 |
! ! |
47 |
||
183 | 48 |
!TestResult class methodsFor:'initialization & release'! |
0 | 49 |
|
50 |
new |
|
104 | 51 |
^super new initialize |
52 |
||
0 | 53 |
! ! |
54 |
||
68 | 55 |
!TestResult methodsFor:'accessing'! |
0 | 56 |
|
57 |
correctCount |
|
104 | 58 |
"depreciated - use #passedCount" |
59 |
||
60 |
^self passedCount |
|
61 |
||
0 | 62 |
! |
63 |
||
64 |
defects |
|
104 | 65 |
^OrderedCollection new |
66 |
addAll: self errors; |
|
67 |
addAll: self failures; yourself |
|
68 |
||
0 | 69 |
! |
70 |
||
71 |
errorCount |
|
104 | 72 |
|
73 |
^self errors size |
|
74 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
75 |
! |
0 | 76 |
|
77 |
errors |
|
104 | 78 |
|
79 |
errors isNil |
|
80 |
ifTrue: [errors := OrderedCollection new]. |
|
81 |
^errors |
|
82 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
83 |
! |
0 | 84 |
|
85 |
failureCount |
|
86 |
||
104 | 87 |
^self failures size |
88 |
||
0 | 89 |
! |
90 |
||
91 |
failures |
|
104 | 92 |
failures isNil |
93 |
ifTrue: [failures := Set new]. |
|
94 |
^failures |
|
95 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
96 |
! |
0 | 97 |
|
53 | 98 |
passed |
104 | 99 |
|
100 |
passed isNil |
|
101 |
ifTrue: [passed := OrderedCollection new]. |
|
102 |
||
103 |
^passed |
|
104 |
||
53 | 105 |
! |
106 |
||
107 |
passedCount |
|
108 |
||
104 | 109 |
^self passed size |
110 |
||
53 | 111 |
! |
112 |
||
0 | 113 |
runCount |
53 | 114 |
|
104 | 115 |
^self passedCount + self failureCount + self errorCount |
116 |
||
53 | 117 |
! |
118 |
||
119 |
tests |
|
104 | 120 |
|
121 |
^(OrderedCollection new: self runCount) |
|
122 |
addAll: self passed; |
|
123 |
addAll: self errors; |
|
124 |
addAll: self failures; |
|
125 |
yourself |
|
126 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
127 |
! ! |
0 | 128 |
|
68 | 129 |
!TestResult methodsFor:'init / release'! |
0 | 130 |
|
131 |
initialize |
|
104 | 132 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
133 |
! ! |
0 | 134 |
|
68 | 135 |
!TestResult methodsFor:'printing'! |
0 | 136 |
|
137 |
printOn: aStream |
|
104 | 138 |
|
139 |
aStream |
|
140 |
nextPutAll: self runCount printString; |
|
141 |
nextPutAll: ' run, '; |
|
142 |
nextPutAll: self correctCount printString; |
|
143 |
nextPutAll: ' passed, '; |
|
144 |
nextPutAll: self failureCount printString; |
|
145 |
nextPutAll: ' failed, '; |
|
146 |
nextPutAll: self errorCount printString; |
|
147 |
nextPutAll: ' error'. |
|
148 |
||
149 |
self errorCount ~= 1 |
|
150 |
ifTrue: [aStream nextPut: $s] |
|
151 |
||
0 | 152 |
! ! |
153 |
||
68 | 154 |
!TestResult methodsFor:'running'! |
0 | 155 |
|
104 | 156 |
runCase:aTestCase |
136 | 157 |
|testCasePassed failure error| |
53 | 158 |
|
136 | 159 |
testCasePassed := true. |
160 |
failure := error := false. |
|
161 |
||
132 | 162 |
[ |
104 | 163 |
[ |
164 |
aTestCase runCase. |
|
136 | 165 |
|
104 | 166 |
] on:self class failure do:[:ex | |
136 | 167 |
testCasePassed ifTrue: |
168 |
[failure := true. |
|
169 |
testCasePassed := false]. |
|
170 |
||
104 | 171 |
ex handleFailureWith:false |
172 |
] |
|
127 | 173 |
] on:self class error do:[:ex | |
174 |
(AbortAllOperationRequest accepts:ex signal) ifTrue:[ |
|
175 |
(AbortOperationRequest accepts:ex signal) ifFalse:[ |
|
176 |
ex reject |
|
177 |
]. |
|
178 |
]. |
|
130 | 179 |
(HaltInterrupt accepts:ex signal) ifTrue:[ |
180 |
ex reject |
|
181 |
]. |
|
136 | 182 |
error := true. |
183 |
testCasePassed := false. |
|
104 | 184 |
ex returnWith:false |
185 |
]. |
|
130 | 186 |
|
136 | 187 |
error |
188 |
ifTrue: |
|
189 |
[self errors add: aTestCase] |
|
190 |
ifFalse: |
|
191 |
[failure ifTrue: [self failures add: aTestCase]]. |
|
192 |
||
104 | 193 |
testCasePassed ifTrue:[ |
194 |
self passed add:aTestCase |
|
195 |
] |
|
130 | 196 |
|
132 | 197 |
"Modified: / 06-08-2006 / 10:42:42 / cg" |
136 | 198 |
"Modified: / 28-08-2006 / 16:40:00 / boris" |
199 |
||
200 |
" a test case should be registered either as passed or as failed or as error. |
|
201 |
Note that several resumable failures may preceed one final error " |
|
0 | 202 |
! ! |
203 |
||
68 | 204 |
!TestResult methodsFor:'testing'! |
0 | 205 |
|
53 | 206 |
hasErrors |
207 |
||
104 | 208 |
^self errors size > 0 |
209 |
||
53 | 210 |
! |
211 |
||
212 |
hasFailures |
|
213 |
||
104 | 214 |
^self failures size > 0 |
215 |
||
53 | 216 |
! |
217 |
||
0 | 218 |
hasPassed |
104 | 219 |
|
220 |
^self hasErrors not and: [self hasFailures not] |
|
221 |
||
53 | 222 |
! |
223 |
||
224 |
isError: aTestCase |
|
225 |
||
104 | 226 |
^self errors includes: aTestCase |
227 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
228 |
! |
0 | 229 |
|
230 |
isFailure: aTestCase |
|
104 | 231 |
^self failures includes: aTestCase |
232 |
||
53 | 233 |
! |
234 |
||
235 |
isPassed: aTestCase |
|
236 |
||
104 | 237 |
^self passed includes: aTestCase |
238 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
239 |
! ! |
0 | 240 |
|
14 | 241 |
!TestResult class methodsFor:'documentation'! |
242 |
||
243 |
version |
|
183 | 244 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestResult.st,v 1.19 2008-09-03 08:50:25 cg Exp $' |
14 | 245 |
! ! |