author | Claus Gittinger <cg@exept.de> |
Thu, 23 Aug 2001 22:57:05 +0200 | |
changeset 27 | a36d465d164c |
parent 22 | 9793b84d0881 |
child 32 | 77f76ea3a7ef |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
Object subclass:#TestCase |
|
4 |
instanceVariableNames:'testSelector' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
7 |
category:'SUnit-Base' |
0 | 8 |
! |
9 |
||
12 | 10 |
|
2 | 11 |
!TestCase class methodsFor:'initialization'! |
12 |
||
13 |
initialize |
|
14 |
"ensure, that the sunit extensions are loaded" |
|
15 |
||
16 |
(Class implements:#sunitName) ifFalse:[ |
|
17 |
Smalltalk fileIn:'extensions.st' inPackage:(self package) |
|
18 |
]. |
|
4 | 19 |
TestFailure isLoaded ifFalse:[ |
20 |
TestFailure autoload |
|
21 |
]. |
|
2 | 22 |
|
23 |
" |
|
24 |
self initialize |
|
4 | 25 |
" |
26 |
! ! |
|
2 | 27 |
|
0 | 28 |
!TestCase class methodsFor:'Instance Creation'! |
29 |
||
30 |
debug: aSymbol |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
31 |
^(self selector: aSymbol) debug |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
32 |
! |
0 | 33 |
|
34 |
run: aSymbol |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
35 |
^(self selector: aSymbol) run |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
36 |
! |
0 | 37 |
|
38 |
selector: aSymbol |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
39 |
^self new setTestSelector: aSymbol |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
40 |
! |
0 | 41 |
|
42 |
suite |
|
22 | 43 |
| testSelectors result | |
44 |
testSelectors := self sunitSelectors select: [:each | 'test*' sunitMatch: each]. |
|
45 |
testSelectors sort. |
|
46 |
result := TestSuite new. |
|
47 |
testSelectors do: [:each | result addTest: (self selector: each)]. |
|
48 |
^result |
|
0 | 49 |
|
50 |
"Modified: / 21.6.2000 / 10:05:24 / Sames" |
|
51 |
! ! |
|
52 |
||
53 |
!TestCase methodsFor:'Accessing'! |
|
54 |
||
55 |
assert: aBoolean |
|
3 | 56 |
"fail, if the argument is not true" |
57 |
||
13 | 58 |
(aBoolean isKindOf:Boolean) ifFalse:[ self error:'non boolean assertion' ]. |
3 | 59 |
aBoolean ifFalse: [self signalFailure: 'Assertion failed'] |
0 | 60 |
|
61 |
"Modified: / 21.6.2000 / 10:00:05 / Sames" |
|
62 |
! |
|
63 |
||
27 | 64 |
assertFalse:aBoolean |
65 |
^ self assert:aBoolean not |
|
66 |
! |
|
67 |
||
68 |
assertFalse:aBoolean named:testName |
|
69 |
^ self assert:aBoolean not |
|
70 |
! |
|
71 |
||
72 |
assertTrue:aBoolean |
|
73 |
^ self assert:aBoolean |
|
74 |
! |
|
75 |
||
76 |
assertTrue:aBoolean named:testName |
|
77 |
^ self assert:aBoolean |
|
78 |
! |
|
79 |
||
0 | 80 |
deny: aBoolean |
3 | 81 |
"fail, if the argument is not false" |
82 |
||
83 |
self assert: aBoolean not |
|
84 |
! |
|
0 | 85 |
|
86 |
should: aBlock |
|
3 | 87 |
"fail, if the block does not evaluate to true" |
88 |
||
89 |
self assert: aBlock value |
|
90 |
! |
|
0 | 91 |
|
92 |
should: aBlock raise: anExceptionalEvent |
|
3 | 93 |
"fail, if the block does not raise the given event" |
94 |
||
95 |
^self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) |
|
0 | 96 |
|
97 |
"Modified: / 21.6.2000 / 10:01:08 / Sames" |
|
98 |
! |
|
99 |
||
100 |
shouldnt: aBlock |
|
3 | 101 |
"fail, if the block does evaluate to true" |
102 |
||
103 |
self deny: aBlock value |
|
104 |
! |
|
0 | 105 |
|
106 |
shouldnt: aBlock raise: anExceptionalEvent |
|
3 | 107 |
"fail, if the block does raise the given event" |
108 |
||
109 |
^self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not |
|
0 | 110 |
|
111 |
"Modified: / 21.6.2000 / 10:01:16 / Sames" |
|
112 |
! |
|
113 |
||
114 |
signalFailure: aString |
|
3 | 115 |
"/ TestResult failure sunitSignalWith: aString |
116 |
TestResult failure raiseErrorString:aString in:thisContext sender sender . |
|
0 | 117 |
|
3 | 118 |
"Modified: / 21.6.2000 / 10:01:34 / Sames" |
119 |
! ! |
|
0 | 120 |
|
121 |
!TestCase methodsFor:'Dependencies'! |
|
122 |
||
123 |
addDependentToHierachy: anObject |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
124 |
"an empty method. for Composite compability with TestSuite" |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
125 |
! |
0 | 126 |
|
127 |
removeDependentFromHierachy: anObject |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
128 |
"an empty method. for Composite compability with TestSuite" |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
129 |
! ! |
0 | 130 |
|
131 |
!TestCase methodsFor:'Printing'! |
|
132 |
||
133 |
printOn: aStream |
|
134 |
aStream nextPutAll: self class name. |
|
135 |
aStream nextPutAll: '>>'. |
|
136 |
aStream nextPutAll: testSelector |
|
137 |
||
138 |
"Modified: / 4.4.2000 / 18:59:53 / Sames" |
|
139 |
! ! |
|
140 |
||
141 |
!TestCase methodsFor:'Private'! |
|
142 |
||
143 |
executeShould: aBlock inScopeOf: anExceptionalEvent |
|
18 | 144 |
[[aBlock value] |
145 |
on: anExceptionalEvent |
|
146 |
do: [:ex | ^true]] |
|
147 |
on: TestResult error |
|
148 |
do: [:ex | ^false]. |
|
149 |
^false. |
|
0 | 150 |
|
151 |
"Modified: / 21.6.2000 / 10:03:03 / Sames" |
|
152 |
! |
|
153 |
||
154 |
setTestSelector: aSymbol |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
155 |
testSelector := aSymbol |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
156 |
! ! |
0 | 157 |
|
158 |
!TestCase methodsFor:'Running'! |
|
159 |
||
160 |
debug |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
161 |
(self class selector: testSelector) runCase |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
162 |
! |
0 | 163 |
|
164 |
debugAsFailure |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
165 |
(self class selector: testSelector) runCaseAsFailure |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
166 |
! |
0 | 167 |
|
168 |
openDebuggerOnFailingTestMethod |
|
1 | 169 |
"SUnit has halted one step in front of the failing test method. |
170 |
Step over the 'self halt' and send into 'self perform: testSelector' |
|
171 |
to see the failure from the beginning" |
|
0 | 172 |
|
1 | 173 |
"/ self halt. |
174 |
self perform: testSelector sunitAsSymbol |
|
0 | 175 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
176 |
"Modified: / 21.6.2000 / 10:03:37 / Sames" |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
177 |
! |
0 | 178 |
|
179 |
run |
|
180 |
| result | |
|
181 |
result := TestResult new. |
|
182 |
self run: result. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
183 |
^result |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
184 |
! |
0 | 185 |
|
186 |
run: aResult |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
187 |
aResult runCase: self |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
188 |
! |
0 | 189 |
|
190 |
runCase |
|
191 |
self setUp. |
|
192 |
[self perform: testSelector sunitAsSymbol] sunitEnsure: [self tearDown] |
|
193 |
||
194 |
"Modified: / 21.6.2000 / 10:04:18 / Sames" |
|
195 |
! |
|
196 |
||
197 |
runCaseAsFailure |
|
198 |
self setUp. |
|
199 |
[[self openDebuggerOnFailingTestMethod] sunitEnsure: [self tearDown]] fork |
|
200 |
||
201 |
"Modified: / 21.6.2000 / 10:04:33 / Sames" |
|
202 |
! |
|
203 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
204 |
setUp |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
205 |
! |
0 | 206 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
207 |
tearDown |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
208 |
! ! |
0 | 209 |
|
12 | 210 |
!TestCase class methodsFor:'documentation'! |
211 |
||
212 |
version |
|
27 | 213 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestCase.st,v 1.11 2001-08-23 20:57:05 cg Exp $' |
12 | 214 |
! ! |
2 | 215 |
TestCase initialize! |