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