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