author | Claus Gittinger <cg@exept.de> |
Tue, 16 Jan 2001 15:45:04 +0100 | |
changeset 22 | 9793b84d0881 |
parent 18 | 0bcd227dc1c6 |
child 27 | a36d465d164c |
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 |
||
64 |
deny: aBoolean |
|
3 | 65 |
"fail, if the argument is not false" |
66 |
||
67 |
self assert: aBoolean not |
|
68 |
! |
|
0 | 69 |
|
70 |
should: aBlock |
|
3 | 71 |
"fail, if the block does not evaluate to true" |
72 |
||
73 |
self assert: aBlock value |
|
74 |
! |
|
0 | 75 |
|
76 |
should: aBlock raise: anExceptionalEvent |
|
3 | 77 |
"fail, if the block does not raise the given event" |
78 |
||
79 |
^self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) |
|
0 | 80 |
|
81 |
"Modified: / 21.6.2000 / 10:01:08 / Sames" |
|
82 |
! |
|
83 |
||
84 |
shouldnt: aBlock |
|
3 | 85 |
"fail, if the block does evaluate to true" |
86 |
||
87 |
self deny: aBlock value |
|
88 |
! |
|
0 | 89 |
|
90 |
shouldnt: aBlock raise: anExceptionalEvent |
|
3 | 91 |
"fail, if the block does raise the given event" |
92 |
||
93 |
^self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not |
|
0 | 94 |
|
95 |
"Modified: / 21.6.2000 / 10:01:16 / Sames" |
|
96 |
! |
|
97 |
||
98 |
signalFailure: aString |
|
3 | 99 |
"/ TestResult failure sunitSignalWith: aString |
100 |
TestResult failure raiseErrorString:aString in:thisContext sender sender . |
|
0 | 101 |
|
3 | 102 |
"Modified: / 21.6.2000 / 10:01:34 / Sames" |
103 |
! ! |
|
0 | 104 |
|
105 |
!TestCase methodsFor:'Dependencies'! |
|
106 |
||
107 |
addDependentToHierachy: anObject |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
108 |
"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
|
109 |
! |
0 | 110 |
|
111 |
removeDependentFromHierachy: anObject |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
112 |
"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
|
113 |
! ! |
0 | 114 |
|
115 |
!TestCase methodsFor:'Printing'! |
|
116 |
||
117 |
printOn: aStream |
|
118 |
aStream nextPutAll: self class name. |
|
119 |
aStream nextPutAll: '>>'. |
|
120 |
aStream nextPutAll: testSelector |
|
121 |
||
122 |
"Modified: / 4.4.2000 / 18:59:53 / Sames" |
|
123 |
! ! |
|
124 |
||
125 |
!TestCase methodsFor:'Private'! |
|
126 |
||
127 |
executeShould: aBlock inScopeOf: anExceptionalEvent |
|
18 | 128 |
[[aBlock value] |
129 |
on: anExceptionalEvent |
|
130 |
do: [:ex | ^true]] |
|
131 |
on: TestResult error |
|
132 |
do: [:ex | ^false]. |
|
133 |
^false. |
|
0 | 134 |
|
135 |
"Modified: / 21.6.2000 / 10:03:03 / Sames" |
|
136 |
! |
|
137 |
||
138 |
setTestSelector: aSymbol |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
139 |
testSelector := aSymbol |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
140 |
! ! |
0 | 141 |
|
142 |
!TestCase methodsFor:'Running'! |
|
143 |
||
144 |
debug |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
145 |
(self class selector: testSelector) runCase |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
146 |
! |
0 | 147 |
|
148 |
debugAsFailure |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
149 |
(self class selector: testSelector) runCaseAsFailure |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
150 |
! |
0 | 151 |
|
152 |
openDebuggerOnFailingTestMethod |
|
1 | 153 |
"SUnit has halted one step in front of the failing test method. |
154 |
Step over the 'self halt' and send into 'self perform: testSelector' |
|
155 |
to see the failure from the beginning" |
|
0 | 156 |
|
1 | 157 |
"/ self halt. |
158 |
self perform: testSelector sunitAsSymbol |
|
0 | 159 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
160 |
"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
|
161 |
! |
0 | 162 |
|
163 |
run |
|
164 |
| result | |
|
165 |
result := TestResult new. |
|
166 |
self run: result. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
167 |
^result |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
168 |
! |
0 | 169 |
|
170 |
run: aResult |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
171 |
aResult runCase: self |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
172 |
! |
0 | 173 |
|
174 |
runCase |
|
175 |
self setUp. |
|
176 |
[self perform: testSelector sunitAsSymbol] sunitEnsure: [self tearDown] |
|
177 |
||
178 |
"Modified: / 21.6.2000 / 10:04:18 / Sames" |
|
179 |
! |
|
180 |
||
181 |
runCaseAsFailure |
|
182 |
self setUp. |
|
183 |
[[self openDebuggerOnFailingTestMethod] sunitEnsure: [self tearDown]] fork |
|
184 |
||
185 |
"Modified: / 21.6.2000 / 10:04:33 / Sames" |
|
186 |
! |
|
187 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
188 |
setUp |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
189 |
! |
0 | 190 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
191 |
tearDown |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
4
diff
changeset
|
192 |
! ! |
0 | 193 |
|
12 | 194 |
!TestCase class methodsFor:'documentation'! |
195 |
||
196 |
version |
|
22 | 197 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestCase.st,v 1.10 2001-01-16 14:45:04 cg Exp $' |
12 | 198 |
! ! |
2 | 199 |
TestCase initialize! |