0
|
1 |
"{ Package: 'stx:goodies/sunit' }"
|
|
2 |
|
|
3 |
Object subclass:#TestCase
|
|
4 |
instanceVariableNames:'testSelector'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'SUnit'
|
|
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
|
|
30 |
^(self selector: aSymbol) debug!
|
|
31 |
|
|
32 |
run: aSymbol
|
|
33 |
^(self selector: aSymbol) run!
|
|
34 |
|
|
35 |
selector: aSymbol
|
|
36 |
^self new setTestSelector: aSymbol!
|
|
37 |
|
|
38 |
suite
|
|
39 |
| testSelectors result |
|
|
40 |
testSelectors := self sunitSelectors select: [:each | 'test*' sunitMatch: each].
|
|
41 |
result := TestSuite new.
|
|
42 |
testSelectors do: [:each | result addTest: (self selector: each)].
|
|
43 |
^result
|
|
44 |
|
|
45 |
"Modified: / 21.6.2000 / 10:05:24 / Sames"
|
|
46 |
! !
|
|
47 |
|
|
48 |
!TestCase methodsFor:'Accessing'!
|
|
49 |
|
|
50 |
assert: aBoolean
|
3
|
51 |
"fail, if the argument is not true"
|
|
52 |
|
|
53 |
(aBoolean isKindOf:Boolean) ifFalse:[ self fail ].
|
|
54 |
aBoolean ifFalse: [self signalFailure: 'Assertion failed']
|
0
|
55 |
|
|
56 |
"Modified: / 21.6.2000 / 10:00:05 / Sames"
|
|
57 |
!
|
|
58 |
|
|
59 |
deny: aBoolean
|
3
|
60 |
"fail, if the argument is not false"
|
|
61 |
|
|
62 |
self assert: aBoolean not
|
|
63 |
!
|
0
|
64 |
|
|
65 |
should: aBlock
|
3
|
66 |
"fail, if the block does not evaluate to true"
|
|
67 |
|
|
68 |
self assert: aBlock value
|
|
69 |
!
|
0
|
70 |
|
|
71 |
should: aBlock raise: anExceptionalEvent
|
3
|
72 |
"fail, if the block does not raise the given event"
|
|
73 |
|
|
74 |
^self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent)
|
0
|
75 |
|
|
76 |
"Modified: / 21.6.2000 / 10:01:08 / Sames"
|
|
77 |
!
|
|
78 |
|
|
79 |
shouldnt: aBlock
|
3
|
80 |
"fail, if the block does evaluate to true"
|
|
81 |
|
|
82 |
self deny: aBlock value
|
|
83 |
!
|
0
|
84 |
|
|
85 |
shouldnt: aBlock raise: anExceptionalEvent
|
3
|
86 |
"fail, if the block does raise the given event"
|
|
87 |
|
|
88 |
^self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not
|
0
|
89 |
|
|
90 |
"Modified: / 21.6.2000 / 10:01:16 / Sames"
|
|
91 |
!
|
|
92 |
|
|
93 |
signalFailure: aString
|
3
|
94 |
"/ TestResult failure sunitSignalWith: aString
|
|
95 |
TestResult failure raiseErrorString:aString in:thisContext sender sender .
|
0
|
96 |
|
3
|
97 |
"Modified: / 21.6.2000 / 10:01:34 / Sames"
|
|
98 |
! !
|
0
|
99 |
|
|
100 |
!TestCase methodsFor:'Dependencies'!
|
|
101 |
|
|
102 |
addDependentToHierachy: anObject
|
|
103 |
"an empty method. for Composite compability with TestSuite"!
|
|
104 |
|
|
105 |
removeDependentFromHierachy: anObject
|
|
106 |
"an empty method. for Composite compability with TestSuite"! !
|
|
107 |
|
|
108 |
!TestCase methodsFor:'Printing'!
|
|
109 |
|
|
110 |
printOn: aStream
|
|
111 |
aStream nextPutAll: self class name.
|
|
112 |
aStream nextPutAll: '>>'.
|
|
113 |
aStream nextPutAll: testSelector
|
|
114 |
|
|
115 |
"Modified: / 4.4.2000 / 18:59:53 / Sames"
|
|
116 |
! !
|
|
117 |
|
|
118 |
!TestCase methodsFor:'Private'!
|
|
119 |
|
|
120 |
executeShould: aBlock inScopeOf: anExceptionalEvent
|
|
121 |
[[aBlock value]
|
|
122 |
sunitOn: anExceptionalEvent
|
|
123 |
do: [:ex | ^true]]
|
|
124 |
sunitOn: TestResult error
|
|
125 |
do: [:ex | ^false].
|
|
126 |
^false.
|
|
127 |
|
|
128 |
"Modified: / 21.6.2000 / 10:03:03 / Sames"
|
|
129 |
!
|
|
130 |
|
|
131 |
setTestSelector: aSymbol
|
|
132 |
testSelector := aSymbol! !
|
|
133 |
|
|
134 |
!TestCase methodsFor:'Running'!
|
|
135 |
|
|
136 |
debug
|
|
137 |
(self class selector: testSelector) runCase!
|
|
138 |
|
|
139 |
debugAsFailure
|
|
140 |
(self class selector: testSelector) runCaseAsFailure!
|
|
141 |
|
|
142 |
openDebuggerOnFailingTestMethod
|
1
|
143 |
"SUnit has halted one step in front of the failing test method.
|
|
144 |
Step over the 'self halt' and send into 'self perform: testSelector'
|
|
145 |
to see the failure from the beginning"
|
0
|
146 |
|
1
|
147 |
"/ self halt.
|
|
148 |
self perform: testSelector sunitAsSymbol
|
0
|
149 |
|
1
|
150 |
"Modified: / 21.6.2000 / 10:03:37 / Sames"!
|
0
|
151 |
|
|
152 |
run
|
|
153 |
| result |
|
|
154 |
result := TestResult new.
|
|
155 |
self run: result.
|
|
156 |
^result!
|
|
157 |
|
|
158 |
run: aResult
|
|
159 |
aResult runCase: self!
|
|
160 |
|
|
161 |
runCase
|
|
162 |
self setUp.
|
|
163 |
[self perform: testSelector sunitAsSymbol] sunitEnsure: [self tearDown]
|
|
164 |
|
|
165 |
"Modified: / 21.6.2000 / 10:04:18 / Sames"
|
|
166 |
!
|
|
167 |
|
|
168 |
runCaseAsFailure
|
|
169 |
self setUp.
|
|
170 |
[[self openDebuggerOnFailingTestMethod] sunitEnsure: [self tearDown]] fork
|
|
171 |
|
|
172 |
"Modified: / 21.6.2000 / 10:04:33 / Sames"
|
|
173 |
!
|
|
174 |
|
|
175 |
setUp!
|
|
176 |
|
|
177 |
tearDown! !
|
|
178 |
|
2
|
179 |
TestCase initialize!
|