author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 03 Sep 2016 09:08:25 +0100 | |
branch | jv |
changeset 664 | e31b2e7b658d |
parent 222 | 8e6f482297fa |
child 724 | 4dae63fce9f9 |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
3 |
"{ NameSpace: Smalltalk }" |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
4 |
|
0 | 5 |
TestCase subclass:#SUnitTest |
6 |
instanceVariableNames:'hasRun hasSetup hasRanOnce' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
9 |
category:'SUnit-Tests' |
0 | 10 |
! |
11 |
||
222 | 12 |
SUnitTest comment:'This is both an example of writing tests and a self test for the SUnit. The tests |
13 |
here are pretty strange, since you want to make sure things blow up. You should |
|
14 |
not generally have to write tests this complicated in structure, although they |
|
15 |
will be far more complicated in terms of your own objects- more assertions, more |
|
16 |
complicated setup. Kent says: "Never forget, however, that if the tests are hard |
|
109 | 17 |
to write, something is probably wrong with the design".' |
18 |
! |
|
9 | 19 |
|
58 | 20 |
|
68 | 21 |
!SUnitTest methodsFor:'accessing'! |
0 | 22 |
|
23 |
hasRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
24 |
^hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
25 |
! |
0 | 26 |
|
27 |
hasSetup |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
28 |
^hasSetup |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
29 |
! ! |
0 | 30 |
|
68 | 31 |
!SUnitTest methodsFor:'private'! |
0 | 32 |
|
58 | 33 |
assertForTestResult: aResult runCount: aRunCount passed: aPassedCount failed: aFailureCount errors: anErrorCount |
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
34 |
self assertForTestResult: aResult runCount: aRunCount passed: aPassedCount failed: aFailureCount errors: anErrorCount skipped: 0 |
58 | 35 |
|
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
36 |
"Modified: / 03-09-2016 / 08:54:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
37 |
! |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
38 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
39 |
assertForTestResult: aResult runCount: aRunCount passed: aPassedCount failed: aFailureCount errors: anErrorCount skipped: skippedCount |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
40 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
41 |
self |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
42 |
assert: aResult runCount = aRunCount; |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
43 |
assert: aResult passedCount = aPassedCount; |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
44 |
assert: aResult failureCount = aFailureCount; |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
45 |
assert: aResult errorCount = anErrorCount; |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
46 |
assert: aResult skippedCount = skippedCount |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
47 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
48 |
"Created: / 03-09-2016 / 08:54:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
58 | 49 |
! |
50 |
||
0 | 51 |
error |
52 |
3 zork |
|
53 |
! |
|
54 |
||
55 |
fail |
|
109 | 56 |
self assert: false |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
57 |
! |
0 | 58 |
|
135 | 59 |
failAndError |
222 | 60 |
self assert: false. |
61 |
self assert: false. " second failure " |
|
62 |
self error. |
|
135 | 63 |
! |
64 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
65 |
noop |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
66 |
! |
0 | 67 |
|
68 |
setRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
69 |
hasRun := true |
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
70 |
! |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
71 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
72 |
skipped |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
73 |
self skipIf: true description: 'Skipped' |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
74 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
75 |
"Created: / 03-09-2016 / 08:55:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
76 |
! ! |
0 | 77 |
|
68 | 78 |
!SUnitTest methodsFor:'running'! |
0 | 79 |
|
80 |
setUp |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
81 |
hasSetup := true |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
82 |
! ! |
0 | 83 |
|
68 | 84 |
!SUnitTest methodsFor:'testing'! |
0 | 85 |
|
109 | 86 |
errorShouldntRaise |
222 | 87 |
self |
88 |
shouldnt: [self someMessageThatIsntUnderstood] |
|
89 |
raise: SUnitNameResolver notificationObject |
|
109 | 90 |
! |
91 |
||
0 | 92 |
testAssert |
93 |
self assert: true. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
94 |
self deny: false |
0 | 95 |
! |
96 |
||
97 |
testDefects |
|
98 |
| result suite error failure | |
|
99 |
suite := TestSuite new. |
|
100 |
suite addTest: (error := self class selector: #error). |
|
101 |
suite addTest: (failure := self class selector: #fail). |
|
102 |
result := suite run. |
|
58 | 103 |
self assert: result defects asArray = (Array with: error with: failure). |
104 |
self |
|
105 |
assertForTestResult: result |
|
106 |
runCount: 2 |
|
107 |
passed: 0 |
|
108 |
failed: 1 |
|
109 |
errors: 1 |
|
0 | 110 |
! |
111 |
||
112 |
testDialectLocalizedException |
|
113 |
||
109 | 114 |
self |
115 |
should: [TestResult signalFailureWith: 'Foo'] |
|
116 |
raise: TestResult failure. |
|
117 |
self |
|
118 |
should: [TestResult signalErrorWith: 'Foo'] |
|
119 |
raise: TestResult error. |
|
0 | 120 |
! |
121 |
||
122 |
testError |
|
109 | 123 |
|
0 | 124 |
| case result | |
109 | 125 |
|
0 | 126 |
case := self class selector: #error. |
127 |
result := case run. |
|
58 | 128 |
self |
129 |
assertForTestResult: result |
|
130 |
runCount: 1 |
|
131 |
passed: 0 |
|
132 |
failed: 0 |
|
109 | 133 |
errors: 1. |
134 |
||
135 |
case := self class selector: #errorShouldntRaise. |
|
136 |
result := case run. |
|
222 | 137 |
self |
109 | 138 |
assertForTestResult: result |
139 |
runCount: 1 |
|
140 |
passed: 0 |
|
141 |
failed: 0 |
|
58 | 142 |
errors: 1 |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
143 |
! |
0 | 144 |
|
145 |
testException |
|
146 |
||
109 | 147 |
self |
148 |
should: [self error: 'foo'] |
|
149 |
raise: TestResult error |
|
0 | 150 |
! |
151 |
||
152 |
testFail |
|
109 | 153 |
|
0 | 154 |
| case result | |
109 | 155 |
|
0 | 156 |
case := self class selector: #fail. |
157 |
result := case run. |
|
109 | 158 |
|
58 | 159 |
self |
160 |
assertForTestResult: result |
|
161 |
runCount: 1 |
|
162 |
passed: 0 |
|
163 |
failed: 1 |
|
164 |
errors: 0 |
|
135 | 165 |
! |
166 |
||
0 | 167 |
testIsNotRerunOnDebug |
109 | 168 |
|
0 | 169 |
| case | |
109 | 170 |
|
0 | 171 |
case := self class selector: #testRanOnlyOnce. |
172 |
case run. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
173 |
case debug |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
174 |
! |
0 | 175 |
|
176 |
testRan |
|
109 | 177 |
|
0 | 178 |
| case | |
109 | 179 |
|
0 | 180 |
case := self class selector: #setRun. |
181 |
case run. |
|
182 |
self assert: case hasSetup. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
183 |
self assert: case hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
184 |
! |
0 | 185 |
|
186 |
testRanOnlyOnce |
|
109 | 187 |
|
0 | 188 |
self assert: hasRanOnce ~= true. |
109 | 189 |
hasRanOnce := true |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
190 |
! |
0 | 191 |
|
192 |
testResult |
|
109 | 193 |
|
0 | 194 |
| case result | |
109 | 195 |
|
0 | 196 |
case := self class selector: #noop. |
197 |
result := case run. |
|
109 | 198 |
|
58 | 199 |
self |
200 |
assertForTestResult: result |
|
201 |
runCount: 1 |
|
202 |
passed: 1 |
|
203 |
failed: 0 |
|
204 |
errors: 0 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
205 |
! |
0 | 206 |
|
207 |
testRunning |
|
208 |
||
222 | 209 |
(SUnitDelay forSeconds: 2) wait |
0 | 210 |
! |
211 |
||
212 |
testShould |
|
109 | 213 |
|
214 |
self |
|
215 |
should: [true]; |
|
216 |
shouldnt: [false] |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
217 |
! |
0 | 218 |
|
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
219 |
testSkip |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
220 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
221 |
| case result | |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
222 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
223 |
case := self class selector: #skipped. |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
224 |
result := case run. |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
225 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
226 |
self |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
227 |
assertForTestResult: result |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
228 |
runCount: 1 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
229 |
passed: 0 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
230 |
failed: 0 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
231 |
errors: 0 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
232 |
skipped: 1 |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
233 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
234 |
"Created: / 03-09-2016 / 08:53:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
235 |
! |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
236 |
|
0 | 237 |
testSuite |
109 | 238 |
|
0 | 239 |
| suite result | |
109 | 240 |
|
0 | 241 |
suite := TestSuite new. |
222 | 242 |
suite |
109 | 243 |
addTest: (self class selector: #noop); |
244 |
addTest: (self class selector: #fail); |
|
245 |
addTest: (self class selector: #error). |
|
246 |
||
0 | 247 |
result := suite run. |
109 | 248 |
|
58 | 249 |
self |
250 |
assertForTestResult: result |
|
251 |
runCount: 3 |
|
252 |
passed: 1 |
|
253 |
failed: 1 |
|
254 |
errors: 1 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
255 |
! ! |
0 | 256 |
|
14 | 257 |
!SUnitTest class methodsFor:'documentation'! |
258 |
||
259 |
version |
|
222 | 260 |
^ '$Header: /cvs/stx/stx/goodies/sunit/SUnitTest.st,v 1.11 2011-06-29 19:15:49 cg Exp $' |
261 |
! |
|
262 |
||
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
263 |
version_HG |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
264 |
|
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
265 |
^ '$Changeset: <not expanded> $' |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
266 |
! |
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
267 |
|
222 | 268 |
version_SVN |
269 |
^ '§Id: SUnitTest.st 214 2011-03-14 12:22:21Z vranyj1 §' |
|
14 | 270 |
! ! |
664
e31b2e7b658d
FIX: Do not treat skipped test as passed!
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
271 |