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