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