author | Claus Gittinger <cg@exept.de> |
Tue, 05 Jul 2011 17:45:47 +0200 | |
changeset 238 | 384805dcb5dd |
parent 222 | 8e6f482297fa |
child 243 | cbce69b15370 |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
Object subclass:#TestSuite |
|
103 | 4 |
instanceVariableNames:'tests resources name' |
0 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
7 |
category:'SUnit-Base' |
0 | 8 |
! |
9 |
||
222 | 10 |
TestSuite comment:'' |
103 | 11 |
! |
14 | 12 |
|
103 | 13 |
|
222 | 14 |
!TestSuite class methodsFor:'instance creation'! |
56 | 15 |
|
16 |
named: aString |
|
103 | 17 |
|
18 |
^self new |
|
19 |
name: aString; |
|
20 |
yourself |
|
56 | 21 |
! ! |
22 |
||
238 | 23 |
!TestSuite class methodsFor:'others'! |
24 |
||
25 |
version_CVS |
|
26 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestSuite.st,v 1.20 2011-07-05 15:45:47 cg Exp $' |
|
27 |
! ! |
|
28 |
||
68 | 29 |
!TestSuite methodsFor:'accessing'! |
0 | 30 |
|
31 |
addTest: aTest |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
32 |
self tests add: aTest |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
33 |
! |
0 | 34 |
|
222 | 35 |
addTests: aCollection |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
36 |
aCollection do: [:eachTest | self addTest: eachTest] |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
37 |
! |
0 | 38 |
|
47 | 39 |
defaultResources |
222 | 40 |
^self tests |
41 |
inject: OrderedCollection new |
|
42 |
into: |
|
43 |
[:coll :testCase | |
|
44 |
testCase resources do: |
|
45 |
[:each | |
|
46 |
(coll includes: each) ifFalse: [coll add: each]]. |
|
47 |
coll] |
|
48 |
! |
|
49 |
||
50 |
getTestName |
|
51 |
^self name |
|
52 |
||
53 |
"Created: / 12-09-2006 / 11:38:09 / cg" |
|
47 | 54 |
! |
55 |
||
37 | 56 |
name |
103 | 57 |
|
222 | 58 |
^name |
37 | 59 |
! |
60 |
||
103 | 61 |
name: aString |
62 |
||
63 |
name := aString |
|
37 | 64 |
! |
65 |
||
137 | 66 |
nameOfTest |
67 |
^ self name |
|
68 |
! |
|
69 |
||
47 | 70 |
resources |
71 |
resources isNil ifTrue: [resources := self defaultResources]. |
|
72 |
^resources |
|
73 |
! |
|
74 |
||
222 | 75 |
resources: someOrderedTestResourceClasses |
76 |
"The parameter should understand reverseDo: and should not contain duplicates." |
|
47 | 77 |
|
222 | 78 |
resources := someOrderedTestResourceClasses |
140 | 79 |
! |
80 |
||
0 | 81 |
tests |
82 |
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
|
83 |
^tests |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
84 |
! ! |
0 | 85 |
|
68 | 86 |
!TestSuite methodsFor:'dependencies'! |
0 | 87 |
|
88 |
addDependentToHierachy: anObject |
|
222 | 89 |
self sunitAddDependent: anObject. |
90 |
self tests do: [ :each | each addDependentToHierachy: anObject] |
|
0 | 91 |
! |
92 |
||
93 |
removeDependentFromHierachy: anObject |
|
222 | 94 |
self sunitRemoveDependent: anObject. |
95 |
self tests do: [ :each | each removeDependentFromHierachy: anObject] |
|
0 | 96 |
! ! |
97 |
||
122 | 98 |
!TestSuite methodsFor:'queries'! |
99 |
||
100 |
isTestCase |
|
101 |
^ false |
|
102 |
! |
|
103 |
||
104 |
isTestSuite |
|
105 |
^ true |
|
106 |
! ! |
|
107 |
||
68 | 108 |
!TestSuite methodsFor:'running'! |
0 | 109 |
|
110 |
run |
|
222 | 111 |
| result | |
112 |
result := TestResult new. |
|
113 |
[self run: result] |
|
114 |
"sunitEnsure: [self resources reverseDo: [:each | each reset]]." |
|
115 |
sunitEnsure: [TestResource resetResources: self resources]. |
|
116 |
^result |
|
103 | 117 |
|
222 | 118 |
"Modified: / 11-09-2010 / 16:47:12 / 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
|
119 |
! |
0 | 120 |
|
222 | 121 |
run:aResult |
122 |
||
123 |
aResult name:name. |
|
124 |
self tests do:[:each | |
|
125 |
self sunitChanged:each. |
|
126 |
each run:aResult |
|
127 |
] |
|
128 |
||
129 |
"Modified: / 19-03-2010 / 08:03:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
40 | 130 |
! |
131 |
||
132 |
run: aResult afterEachDo:block2 |
|
133 |
||
222 | 134 |
aResult name: name. |
135 |
self tests do: |
|
136 |
[:each | |
|
137 |
self changed: each. |
|
138 |
each run: aResult afterEachDo:block2] |
|
139 |
||
140 |
"Modified: / 21-06-2000 / 10:14:01 / Sames" |
|
141 |
"Modified: / 19-03-2010 / 08:01:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
62 | 142 |
! |
143 |
||
222 | 144 |
run:aResult beforeEachDo:block1 afterEachDo:block2 |
145 |
|class| |
|
202 | 146 |
|
222 | 147 |
aResult name: name. |
148 |
class := name ifNotNil:[ Smalltalk classNamed:name ] ifNil:[ nil ]. |
|
149 |
class ifNotNil:[ class perform:#setUp ifNotUnderstood:nil ]. |
|
150 |
[ |
|
151 |
self tests do:[:each | |
|
152 |
self sunitChanged:each. |
|
153 |
block1 value:each value:aResult. |
|
154 |
each |
|
155 |
run:aResult |
|
156 |
beforeEachDo:block1 |
|
157 |
afterEachDo:block2. |
|
202 | 158 |
|
222 | 159 |
"/ each run: aResult. |
160 |
||
161 |
block2 value:each value:aResult. |
|
162 |
]. |
|
163 |
] ensure:[ |
|
164 |
self resources do:[:e | |
|
165 |
e reset |
|
166 |
] |
|
167 |
]. |
|
168 |
class ifNotNil:[ class perform:#tearDown ifNotUnderstood:nil ] |
|
169 |
||
170 |
"Modified: / 19-03-2010 / 08:02:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
122 | 171 |
! |
172 |
||
222 | 173 |
run:aResult beforeEachTestCaseDo:block1 afterEachTestCaseDo:block2 |
174 |
||
175 |
aResult name: name. |
|
176 |
self tests do:[:each | |
|
177 |
self changed:each. |
|
178 |
each |
|
179 |
run:aResult |
|
180 |
beforeEachTestCaseDo:block1 |
|
181 |
afterEachTestCaseDo:block2. |
|
182 |
] |
|
183 |
||
184 |
"Modified: / 19-03-2010 / 08:02:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
185 |
! |
|
186 |
||
187 |
runAfterEachDo: aBlock |
|
188 |
| result | |
|
189 |
result := TestResult new. |
|
190 |
result name: name. |
|
191 |
[self run: result afterEachDo: aBlock] |
|
192 |
sunitEnsure: [self resources reverseDo: [:each | each reset]]. |
|
193 |
^result |
|
194 |
||
195 |
"Created: / 15-03-2010 / 20:36:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
196 |
"Modified: / 19-03-2010 / 08:02:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
238 | 197 |
! |
198 |
||
199 |
runBeforeEachDo:block1 afterEachDo: block2 |
|
200 |
| result | |
|
201 |
result := TestResult new. |
|
202 |
result name: name. |
|
203 |
[self run: result beforeEachDo:block1 afterEachDo: block2] |
|
204 |
sunitEnsure: [self resources reverseDo: [:each | each reset]]. |
|
205 |
^result |
|
206 |
||
207 |
"Modified: / 19-03-2010 / 08:02:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
208 |
"Created: / 05-07-2011 / 16:51:25 / cg" |
|
0 | 209 |
! ! |
210 |
||
68 | 211 |
!TestSuite methodsFor:'testing'! |
49 | 212 |
|
213 |
areAllResourcesAvailable |
|
222 | 214 |
^self resources |
49 | 215 |
inject: true |
216 |
into: [:total :each | each isAvailable & total] |
|
103 | 217 |
! |
218 |
||
219 |
signalUnavailableResources |
|
220 |
||
222 | 221 |
self resources do:[:res | |
222 |
res isAvailable ifFalse:[ |
|
223 |
^ res signalInitializationError |
|
224 |
] |
|
103 | 225 |
]. |
49 | 226 |
! ! |
227 |
||
14 | 228 |
!TestSuite class methodsFor:'documentation'! |
229 |
||
230 |
version |
|
238 | 231 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestSuite.st,v 1.20 2011-07-05 15:45:47 cg Exp $' |
222 | 232 |
! |
233 |
||
234 |
version_SVN |
|
235 |
^ '§Id: TestSuite.st 203 2010-09-11 14:49:03Z vranyj1 §' |
|
14 | 236 |
! ! |