author | boris |
Thu, 31 Aug 2006 11:23:00 +0200 | |
changeset 137 | b6e0d451b091 |
parent 122 | 61e456491017 |
child 140 | d61c515f8a58 |
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 |
||
103 | 10 |
TestSuite comment:'This is a Composite of Tests, either TestCases or other TestSuites. The common protocol is #run: aTestResult and the dependencies protocol' |
11 |
! |
|
14 | 12 |
|
103 | 13 |
|
14 |
!TestSuite class methodsFor:'Creation'! |
|
56 | 15 |
|
16 |
named: aString |
|
103 | 17 |
|
18 |
^self new |
|
19 |
name: aString; |
|
20 |
yourself |
|
21 |
||
56 | 22 |
! ! |
23 |
||
68 | 24 |
!TestSuite methodsFor:'accessing'! |
0 | 25 |
|
26 |
addTest: aTest |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
27 |
self tests add: aTest |
103 | 28 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
29 |
! |
0 | 30 |
|
31 |
addTests: aCollection |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
32 |
aCollection do: [:eachTest | self addTest: eachTest] |
103 | 33 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
34 |
! |
0 | 35 |
|
47 | 36 |
defaultResources |
37 |
^self tests |
|
38 |
inject: Set new |
|
103 | 39 |
into: [:coll :testCase | |
47 | 40 |
coll |
41 |
addAll: testCase resources; |
|
42 |
yourself] |
|
103 | 43 |
|
47 | 44 |
! |
45 |
||
37 | 46 |
name |
103 | 47 |
|
37 | 48 |
^ name ? 'a TestSuite'. |
49 |
! |
|
50 |
||
103 | 51 |
name: aString |
52 |
||
53 |
name := aString |
|
54 |
||
37 | 55 |
! |
56 |
||
137 | 57 |
nameOfTest |
58 |
^ self name |
|
59 |
! |
|
60 |
||
47 | 61 |
resources |
62 |
resources isNil ifTrue: [resources := self defaultResources]. |
|
63 |
^resources |
|
103 | 64 |
|
47 | 65 |
! |
66 |
||
67 |
resources: anObject |
|
68 |
resources := anObject |
|
103 | 69 |
|
47 | 70 |
! |
71 |
||
0 | 72 |
tests |
73 |
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
|
74 |
^tests |
103 | 75 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
76 |
! ! |
0 | 77 |
|
68 | 78 |
!TestSuite methodsFor:'dependencies'! |
0 | 79 |
|
80 |
addDependentToHierachy: anObject |
|
32 | 81 |
self addDependent: anObject. |
103 | 82 |
self tests do: [ :each | each addDependentToHierachy: anObject] |
0 | 83 |
! |
84 |
||
85 |
removeDependentFromHierachy: anObject |
|
32 | 86 |
self removeDependent: anObject. |
103 | 87 |
self tests do: [ :each | each removeDependentFromHierachy: anObject] |
0 | 88 |
! ! |
89 |
||
122 | 90 |
!TestSuite methodsFor:'queries'! |
91 |
||
92 |
isTestCase |
|
93 |
^ false |
|
94 |
! |
|
95 |
||
96 |
isTestSuite |
|
97 |
^ true |
|
98 |
! ! |
|
99 |
||
68 | 100 |
!TestSuite methodsFor:'running'! |
0 | 101 |
|
102 |
run |
|
49 | 103 |
| result | |
103 | 104 |
|
105 |
self signalUnavailableResources. |
|
106 |
||
49 | 107 |
result := TestResult new. |
108 |
[self run: result] ensure: [self resources do: [:each | each reset]]. |
|
109 |
^result |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
110 |
! |
0 | 111 |
|
112 |
run: aResult |
|
103 | 113 |
self tests do: [:each | |
32 | 114 |
self changed: each. |
115 |
each run: aResult] |
|
40 | 116 |
! |
117 |
||
118 |
run: aResult afterEachDo:block2 |
|
119 |
self tests do: |
|
120 |
[:each | |
|
121 |
self changed: each. |
|
122 | 122 |
each run: aResult afterEachDo:block2. |
123 |
"/ block2 value:each value:aResult |
|
40 | 124 |
] |
125 |
||
126 |
"Modified: / 21.6.2000 / 10:14:01 / Sames" |
|
62 | 127 |
! |
128 |
||
129 |
run: aResult beforeEachDo:block1 afterEachDo:block2 |
|
130 |
self tests do: |
|
131 |
[:each | |
|
132 |
self changed: each. |
|
133 |
block1 value:each value:aResult. |
|
134 |
each run: aResult beforeEachDo:block1 afterEachDo:block2. |
|
135 |
"/ each run: aResult. |
|
136 |
block2 value:each value:aResult. |
|
137 |
] |
|
122 | 138 |
! |
139 |
||
140 |
run: aResult beforeEachTestCaseDo:block1 afterEachTestCaseDo:block2 |
|
141 |
self tests do: |
|
142 |
[:each | |
|
143 |
self changed: each. |
|
144 |
each run: aResult beforeEachTestCaseDo:block1 afterEachTestCaseDo:block2. |
|
145 |
] |
|
0 | 146 |
! ! |
147 |
||
68 | 148 |
!TestSuite methodsFor:'testing'! |
49 | 149 |
|
150 |
areAllResourcesAvailable |
|
151 |
^self resources |
|
152 |
inject: true |
|
153 |
into: [:total :each | each isAvailable & total] |
|
103 | 154 |
! |
155 |
||
156 |
signalUnavailableResources |
|
157 |
||
158 |
self resources do:[:res | |
|
159 |
res isAvailable ifFalse:[ |
|
160 |
^ res signalInitializationError |
|
161 |
] |
|
162 |
]. |
|
49 | 163 |
! ! |
164 |
||
14 | 165 |
!TestSuite class methodsFor:'documentation'! |
166 |
||
167 |
version |
|
137 | 168 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestSuite.st,v 1.15 2006-08-31 09:23:00 boris Exp $' |
14 | 169 |
! ! |