author | Claus Gittinger <cg@exept.de> |
Sun, 07 Jul 2019 14:54:40 +0200 | |
changeset 754 | a40cfdc417ad |
parent 740 | 7f2cc93c7a75 |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
602 | 3 |
"{ NameSpace: Smalltalk }" |
4 |
||
0 | 5 |
Object subclass:#TestSuite |
103 | 6 |
instanceVariableNames:'tests resources name' |
0 | 7 |
classVariableNames:'' |
8 |
poolDictionaries:'' |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
9 |
category:'SUnit-Base' |
0 | 10 |
! |
11 |
||
222 | 12 |
TestSuite comment:'' |
103 | 13 |
! |
14 | 14 |
|
103 | 15 |
|
222 | 16 |
!TestSuite class methodsFor:'instance creation'! |
56 | 17 |
|
18 |
named: aString |
|
103 | 19 |
|
20 |
^self new |
|
21 |
name: aString; |
|
22 |
yourself |
|
56 | 23 |
! ! |
24 |
||
68 | 25 |
!TestSuite methodsFor:'accessing'! |
0 | 26 |
|
27 |
addTest: aTest |
|
450 | 28 |
self tests add: aTest |
437 | 29 |
|
30 |
"Modified: / 16-01-2012 / 14:07:03 / cg" |
|
450 | 31 |
"Modified: / 02-08-2012 / 11:56:19 / 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
|
32 |
! |
0 | 33 |
|
222 | 34 |
addTests: aCollection |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
35 |
aCollection do: [:eachTest | self addTest: eachTest] |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
36 |
! |
0 | 37 |
|
701 | 38 |
countTests |
39 |
^ (tests ? #()) inject:0 into:[:count :test | count + test countTests] |
|
40 |
||
41 |
"Created: / 04-08-2011 / 13:03:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
42 |
! |
|
43 |
||
47 | 44 |
defaultResources |
222 | 45 |
^self tests |
46 |
inject: OrderedCollection new |
|
47 |
into: |
|
48 |
[:coll :testCase | |
|
49 |
testCase resources do: |
|
50 |
[:each | |
|
51 |
(coll includes: each) ifFalse: [coll add: each]]. |
|
52 |
coll] |
|
53 |
! |
|
54 |
||
55 |
getTestName |
|
56 |
^self name |
|
57 |
||
58 |
"Created: / 12-09-2006 / 11:38:09 / cg" |
|
47 | 59 |
! |
60 |
||
37 | 61 |
name |
103 | 62 |
|
222 | 63 |
^name |
37 | 64 |
! |
65 |
||
103 | 66 |
name: aString |
67 |
||
68 |
name := aString |
|
37 | 69 |
! |
70 |
||
137 | 71 |
nameOfTest |
72 |
^ self name |
|
73 |
! |
|
74 |
||
47 | 75 |
resources |
76 |
resources isNil ifTrue: [resources := self defaultResources]. |
|
77 |
^resources |
|
78 |
! |
|
79 |
||
222 | 80 |
resources: someOrderedTestResourceClasses |
81 |
"The parameter should understand reverseDo: and should not contain duplicates." |
|
47 | 82 |
|
222 | 83 |
resources := someOrderedTestResourceClasses |
140 | 84 |
! |
85 |
||
702 | 86 |
testCount |
87 |
"obsoleted, because all methods starting with 'test' |
|
88 |
are considered to be tests; so this is a bad name; |
|
704 | 89 |
please use countTests. |
90 |
See TestCase >> isTestSelector:" |
|
702 | 91 |
|
92 |
^ self countTests |
|
93 |
! |
|
94 |
||
0 | 95 |
tests |
96 |
tests isNil ifTrue: [tests := OrderedCollection new]. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
97 |
^tests |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
98 |
! ! |
0 | 99 |
|
68 | 100 |
!TestSuite methodsFor:'dependencies'! |
0 | 101 |
|
102 |
addDependentToHierachy: anObject |
|
222 | 103 |
self sunitAddDependent: anObject. |
104 |
self tests do: [ :each | each addDependentToHierachy: anObject] |
|
0 | 105 |
! |
106 |
||
107 |
removeDependentFromHierachy: anObject |
|
222 | 108 |
self sunitRemoveDependent: anObject. |
109 |
self tests do: [ :each | each removeDependentFromHierachy: anObject] |
|
0 | 110 |
! ! |
111 |
||
691 | 112 |
!TestSuite methodsFor:'printing'! |
113 |
||
114 |
printOn:aStream |
|
115 |
aStream |
|
116 |
nextPutAll:self class nameWithoutPrefix; |
|
117 |
nextPutAll:'['; |
|
118 |
nextPutAll:self name ? '???'; |
|
119 |
nextPutAll:']'. |
|
120 |
! ! |
|
121 |
||
122 | 122 |
!TestSuite methodsFor:'queries'! |
123 |
||
754 | 124 |
allCoveredClasses |
125 |
"return a collection of classes which are covered by the selected |
|
126 |
tests. Requires that the testcase returns a non-empty collection |
|
127 |
from the coveredClasses query" |
|
128 |
||
129 |
|testedClasses| |
|
130 |
||
131 |
testedClasses := Set new. |
|
132 |
||
133 |
self tests do:[:eachTest | |
|
134 |
testedClasses addAll:(eachTest class coveredClasses). |
|
135 |
]. |
|
136 |
^ testedClasses |
|
122 | 137 |
! |
138 |
||
754 | 139 |
areAllResourcesAvailable |
140 |
^self resources |
|
141 |
inject: true |
|
142 |
into: [:total :each | each isAvailable & total] |
|
143 |
! |
|
144 |
||
145 |
signalUnavailableResources |
|
146 |
||
147 |
self resources do:[:res | |
|
148 |
res isAvailable ifFalse:[ |
|
149 |
^ res signalInitializationError |
|
150 |
] |
|
151 |
]. |
|
122 | 152 |
! ! |
153 |
||
68 | 154 |
!TestSuite methodsFor:'running'! |
0 | 155 |
|
602 | 156 |
debug |
157 |
||
158 |
^self run: TestResult defaultResultClass new debug:true. |
|
159 |
! |
|
160 |
||
0 | 161 |
run |
103 | 162 |
|
459
d2862af59031
use TestResultForSTX in SUnit runner
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
163 |
^self run: TestResult defaultResultClass new. |
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
164 |
|
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
165 |
"Modified: / 29-07-2011 / 09:34: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
|
166 |
! |
0 | 167 |
|
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
168 |
run:aTestResult |
222 | 169 |
|
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
170 |
^self run: aTestResult |
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
171 |
beforeEachDo: [:test :result|] |
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
172 |
afterEachDo: [:test :result|] |
222 | 173 |
|
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
174 |
"Modified: / 29-07-2011 / 09:59:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
40 | 175 |
! |
176 |
||
740 | 177 |
run:aResult beforeEachDo: before afterEachDo: after |
178 |
"run and fill (update) aResult" |
|
179 |
||
280
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
180 |
^ self |
740 | 181 |
run:aResult |
280
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
182 |
beforeEachDo:before afterEachDo:after |
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
183 |
resetResources:true |
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
184 |
|
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
185 |
"Modified: / 29-07-2011 / 12:09:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
186 |
"Modified: / 31-07-2011 / 13:58:08 / cg" |
740 | 187 |
"Modified (comment): / 28-03-2019 / 13:22:11 / Claus Gittinger" |
280
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
188 |
! |
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
189 |
|
432 | 190 |
run:result beforeEachDo: before afterEachDo: after debug:doDebug |
191 |
^ self |
|
192 |
run:result |
|
193 |
beforeEachDo:before afterEachDo:after |
|
194 |
resetResources:true |
|
195 |
debug:doDebug |
|
196 |
||
197 |
"Modified: / 29-07-2011 / 12:09:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
198 |
"Modified: / 31-07-2011 / 13:58:08 / cg" |
|
199 |
"Created: / 21-08-2011 / 17:56:57 / cg" |
|
200 |
! |
|
201 |
||
280
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
202 |
run:result beforeEachDo:before afterEachDo:after resetResources:resetResources |
740 | 203 |
"run and fill (update) aResult" |
204 |
||
432 | 205 |
^ self |
206 |
run:result |
|
207 |
beforeEachDo:before |
|
208 |
afterEachDo:after |
|
209 |
resetResources:resetResources |
|
210 |
debug:false |
|
211 |
||
212 |
"Created: / 31-07-2011 / 13:57:25 / cg" |
|
213 |
"Modified: / 03-08-2011 / 14:11:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
214 |
"Modified: / 21-08-2011 / 17:56:16 / cg" |
|
740 | 215 |
"Modified (comment): / 28-03-2019 / 13:23:04 / Claus Gittinger" |
432 | 216 |
! |
217 |
||
218 |
run:result beforeEachDo:before afterEachDo:after resetResources:resetResources debug:doDebug |
|
740 | 219 |
"Run each testcase and updating result. |
220 |
If resetResources is true, then the resources are reset, otherwise not" |
|
221 |
||
271
6b971d5e95b8
changed: #run:beforeEachDo:afterEachDo:
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
222 |
result timestamp:(Timestamp now). |
503 | 223 |
result name isNil ifTrue:[ result name:name ]. "will only change once" |
222 | 224 |
[ |
243
cbce69b15370
changed: #run:beforeEachDo:afterEachDo:
Claus Gittinger <cg@exept.de>
parents:
238
diff
changeset
|
225 |
self tests do:[:each | |
cbce69b15370
changed: #run:beforeEachDo:afterEachDo:
Claus Gittinger <cg@exept.de>
parents:
238
diff
changeset
|
226 |
self sunitChanged:each. |
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
227 |
each run:result |
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
228 |
beforeEachDo: before |
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
229 |
afterEachDo: after |
432 | 230 |
resetResources: false "I'll reset it, see the ensure below" |
231 |
debug:doDebug |
|
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
232 |
] |
683 | 233 |
] ensure:[ |
280
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
234 |
resetResources ifTrue:[ |
f64ce19e2b41
added: #run:beforeEachDo:afterEachDo:resetResources:
Claus Gittinger <cg@exept.de>
parents:
271
diff
changeset
|
235 |
TestResource resetResources: self resources |
301
921572c655e1
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
281
diff
changeset
|
236 |
]. |
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
237 |
]. |
480
b6a4cee3ac7e
changed: #run:beforeEachDo:afterEachDo:resetResources:debug:
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
238 |
result endTime:(Timestamp now). |
202 | 239 |
|
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
240 |
^result |
222 | 241 |
|
301
921572c655e1
TestResult refactoring - now it allow for more fine-grained customization
vrany
parents:
281
diff
changeset
|
242 |
"Modified: / 03-08-2011 / 14:11:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
432 | 243 |
"Created: / 21-08-2011 / 17:56:00 / cg" |
683 | 244 |
"Modified: / 13-07-2017 / 14:03:29 / cg" |
740 | 245 |
"Modified (comment): / 28-03-2019 / 13:25:46 / Claus Gittinger" |
122 | 246 |
! |
247 |
||
222 | 248 |
run:aResult beforeEachTestCaseDo:block1 afterEachTestCaseDo:block2 |
249 |
||
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
250 |
<resource: #obsolete> |
222 | 251 |
|
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
252 |
^self run: aResult beforeEachDo: block1 afterEachDo: block2 |
222 | 253 |
|
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
254 |
"Modified: / 29-07-2011 / 09:49:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
238 | 255 |
! |
256 |
||
602 | 257 |
run:aTestResult debug:debug |
258 |
||
259 |
^self run: aTestResult |
|
260 |
beforeEachDo: [:test :result|] |
|
261 |
afterEachDo: [:test :result|] |
|
262 |
debug:debug |
|
263 |
! |
|
264 |
||
281 | 265 |
runBeforeEachDo:block1 |
266 |
||
267 |
^self runBeforeEachDo:block1 afterEachDo:[] |
|
268 |
||
269 |
"Modified: / 29-07-2011 / 09:51:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
270 |
"Created: / 01-08-2011 / 09:42:29 / cg" |
|
271 |
! |
|
272 |
||
238 | 273 |
runBeforeEachDo:block1 afterEachDo: block2 |
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
274 |
|
459
d2862af59031
use TestResultForSTX in SUnit runner
Claus Gittinger <cg@exept.de>
parents:
450
diff
changeset
|
275 |
^self run: TestResult defaultResultClass new beforeEachDo: block1 afterEachDo: block2 |
238 | 276 |
|
277 |
"Created: / 05-07-2011 / 16:51:25 / cg" |
|
263
31c7107b5edd
TestSuite/TestCase run* method refactored (cleanup, possible bug fixes)
vrany
parents:
243
diff
changeset
|
278 |
"Modified: / 29-07-2011 / 09:51:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 279 |
! ! |
280 |
||
68 | 281 |
!TestSuite methodsFor:'testing'! |
49 | 282 |
|
754 | 283 |
isTestCase |
284 |
^ false |
|
103 | 285 |
! |
286 |
||
754 | 287 |
isTestSuite |
288 |
^ true |
|
49 | 289 |
! ! |
290 |
||
14 | 291 |
!TestSuite class methodsFor:'documentation'! |
292 |
||
704 | 293 |
version |
294 |
^ '$Header$' |
|
295 |
! |
|
296 |
||
243
cbce69b15370
changed: #run:beforeEachDo:afterEachDo:
Claus Gittinger <cg@exept.de>
parents:
238
diff
changeset
|
297 |
version_CVS |
683 | 298 |
^ '$Header$' |
222 | 299 |
! |
300 |
||
301 |
version_SVN |
|
683 | 302 |
^ '$Id$' |
14 | 303 |
! ! |
602 | 304 |