author | Claus Gittinger <cg@exept.de> |
Fri, 14 Dec 2001 00:40:21 +0100 | |
changeset 58 | 6fc01534c854 |
parent 52 | e107aeb7b5b7 |
child 68 | 9fd111438d60 |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
TestCase subclass:#SUnitTest |
|
4 |
instanceVariableNames:'hasRun hasSetup hasRanOnce' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
7 |
category:'SUnit-Tests' |
0 | 8 |
! |
9 |
||
9 | 10 |
!SUnitTest class methodsFor:'documentation'! |
11 |
||
12 |
description |
|
13 |
^ 'Tests SUnit itself |
|
14 |
Two tests should fail.' |
|
15 |
! ! |
|
16 |
||
58 | 17 |
!SUnitTest class methodsFor:'Testing'! |
18 |
||
19 |
shouldInheritSelectors |
|
20 |
"answer true to inherit selectors from superclasses" |
|
21 |
||
22 |
^false |
|
23 |
! ! |
|
24 |
||
0 | 25 |
!SUnitTest methodsFor:'Accessing'! |
26 |
||
27 |
hasRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
28 |
^hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
29 |
! |
0 | 30 |
|
31 |
hasSetup |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
32 |
^hasSetup |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
33 |
! ! |
0 | 34 |
|
35 |
!SUnitTest methodsFor:'Private'! |
|
36 |
||
58 | 37 |
assertForTestResult: aResult runCount: aRunCount passed: aPassedCount failed: aFailureCount errors: anErrorCount |
38 |
||
39 |
self |
|
40 |
assert: aResult runCount = aRunCount; |
|
41 |
assert: aResult passedCount = aPassedCount; |
|
42 |
assert: aResult failureCount = aFailureCount; |
|
43 |
assert: aResult errorCount = anErrorCount |
|
44 |
! |
|
45 |
||
0 | 46 |
error |
47 |
3 zork |
|
48 |
||
49 |
"Modified: / 21.6.2000 / 10:22:18 / Sames" |
|
50 |
! |
|
51 |
||
52 |
fail |
|
52 | 53 |
"force a failure" |
54 |
self assert: false |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
55 |
! |
0 | 56 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
57 |
noop |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
58 |
! |
0 | 59 |
|
60 |
setRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
61 |
hasRun := true |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
62 |
! ! |
0 | 63 |
|
64 |
!SUnitTest methodsFor:'Running'! |
|
65 |
||
66 |
setUp |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
67 |
hasSetup := true |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
68 |
! ! |
0 | 69 |
|
70 |
!SUnitTest methodsFor:'Testing'! |
|
71 |
||
72 |
testAssert |
|
73 |
self assert: true. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
74 |
self deny: false |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
75 |
! |
0 | 76 |
|
77 |
testDebugUI |
|
78 |
"This should break" |
|
79 |
3 zork |
|
80 |
||
81 |
"Modified: / 21.6.2000 / 10:22:50 / Sames" |
|
82 |
! |
|
83 |
||
84 |
testDefects |
|
85 |
| result suite error failure | |
|
86 |
suite := TestSuite new. |
|
87 |
suite addTest: (error := self class selector: #error). |
|
88 |
suite addTest: (failure := self class selector: #fail). |
|
89 |
result := suite run. |
|
58 | 90 |
self assert: result defects asArray = (Array with: error with: failure). |
91 |
self |
|
92 |
assertForTestResult: result |
|
93 |
runCount: 2 |
|
94 |
passed: 0 |
|
95 |
failed: 1 |
|
96 |
errors: 1 |
|
0 | 97 |
! |
98 |
||
99 |
testDialectLocalizedException |
|
100 |
self should: [TestResult signalFailureWith: 'Foo'] raise: TestResult failure. |
|
101 |
self should: [TestResult signalErrorWith: 'Foo'] raise: TestResult error. |
|
102 |
self shouldnt: [TestResult signalErrorWith: 'Foo'] raise: TestResult failure. |
|
103 |
||
104 |
"Modified: / 21.6.2000 / 10:23:20 / Sames" |
|
105 |
! |
|
106 |
||
107 |
testError |
|
108 |
| case result | |
|
109 |
case := self class selector: #error. |
|
110 |
result := case run. |
|
58 | 111 |
self |
112 |
assertForTestResult: result |
|
113 |
runCount: 1 |
|
114 |
passed: 0 |
|
115 |
failed: 0 |
|
116 |
errors: 1 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
117 |
! |
0 | 118 |
|
119 |
testException |
|
120 |
self should: [self error: 'foo'] raise: TestResult error |
|
121 |
||
122 |
"Modified: / 21.6.2000 / 10:23:39 / Sames" |
|
123 |
! |
|
124 |
||
125 |
testFail |
|
126 |
| case result | |
|
127 |
case := self class selector: #fail. |
|
128 |
result := case run. |
|
58 | 129 |
self |
130 |
assertForTestResult: result |
|
131 |
runCount: 1 |
|
132 |
passed: 0 |
|
133 |
failed: 1 |
|
134 |
errors: 0 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
135 |
! |
0 | 136 |
|
137 |
testFailureDebugUI |
|
138 |
"This should fail !!" |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
139 |
self fail |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
140 |
! |
0 | 141 |
|
142 |
testIsNotRerunOnDebug |
|
143 |
| case | |
|
144 |
case := self class selector: #testRanOnlyOnce. |
|
145 |
case run. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
146 |
case debug |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
147 |
! |
0 | 148 |
|
149 |
testRan |
|
150 |
| case | |
|
151 |
case := self class selector: #setRun. |
|
152 |
case run. |
|
153 |
self assert: case hasSetup. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
154 |
self assert: case hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
155 |
! |
0 | 156 |
|
157 |
testRanOnlyOnce |
|
158 |
self assert: hasRanOnce ~= true. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
159 |
hasRanOnce := true. |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
160 |
! |
0 | 161 |
|
162 |
testResult |
|
163 |
| case result | |
|
164 |
case := self class selector: #noop. |
|
165 |
result := case run. |
|
58 | 166 |
self |
167 |
assertForTestResult: result |
|
168 |
runCount: 1 |
|
169 |
passed: 1 |
|
170 |
failed: 0 |
|
171 |
errors: 0 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
172 |
! |
0 | 173 |
|
174 |
testRunning |
|
175 |
(SUnitDelay forSeconds: 2) wait |
|
176 |
||
177 |
"Modified: / 21.6.2000 / 10:24:41 / Sames" |
|
178 |
! |
|
179 |
||
180 |
testShould |
|
181 |
self should: [true]. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
182 |
self shouldnt: [false] |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
183 |
! |
0 | 184 |
|
185 |
testSuite |
|
186 |
| suite result | |
|
187 |
suite := TestSuite new. |
|
188 |
suite addTest: (self class selector: #noop). |
|
189 |
suite addTest: (self class selector: #fail). |
|
58 | 190 |
suite addTest: (self class selector: #error). |
0 | 191 |
result := suite run. |
58 | 192 |
self |
193 |
assertForTestResult: result |
|
194 |
runCount: 3 |
|
195 |
passed: 1 |
|
196 |
failed: 1 |
|
197 |
errors: 1 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
198 |
! ! |
0 | 199 |
|
14 | 200 |
!SUnitTest class methodsFor:'documentation'! |
201 |
||
202 |
version |
|
58 | 203 |
^ '$Header: /cvs/stx/stx/goodies/sunit/SUnitTest.st,v 1.7 2001-12-13 23:40:21 cg Exp $' |
14 | 204 |
! ! |