author | convert-repo |
Wed, 29 May 2019 03:28:44 +0000 | |
changeset 751 | 8bfef76c9bb3 |
parent 222 | 8e6f482297fa |
child 611 | 1eecc860f4a5 |
child 664 | e31b2e7b658d |
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 |
||
222 | 10 |
SUnitTest comment:'This is both an example of writing tests and a self test for the SUnit. The tests |
11 |
here are pretty strange, since you want to make sure things blow up. You should |
|
12 |
not generally have to write tests this complicated in structure, although they |
|
13 |
will be far more complicated in terms of your own objects- more assertions, more |
|
14 |
complicated setup. Kent says: "Never forget, however, that if the tests are hard |
|
109 | 15 |
to write, something is probably wrong with the design".' |
16 |
! |
|
9 | 17 |
|
58 | 18 |
|
68 | 19 |
!SUnitTest methodsFor:'accessing'! |
0 | 20 |
|
21 |
hasRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
22 |
^hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
23 |
! |
0 | 24 |
|
25 |
hasSetup |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
26 |
^hasSetup |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
27 |
! ! |
0 | 28 |
|
68 | 29 |
!SUnitTest methodsFor:'private'! |
0 | 30 |
|
58 | 31 |
assertForTestResult: aResult runCount: aRunCount passed: aPassedCount failed: aFailureCount errors: anErrorCount |
32 |
||
33 |
self |
|
34 |
assert: aResult runCount = aRunCount; |
|
35 |
assert: aResult passedCount = aPassedCount; |
|
36 |
assert: aResult failureCount = aFailureCount; |
|
37 |
assert: aResult errorCount = anErrorCount |
|
38 |
! |
|
39 |
||
0 | 40 |
error |
41 |
3 zork |
|
42 |
! |
|
43 |
||
44 |
fail |
|
109 | 45 |
self assert: false |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
46 |
! |
0 | 47 |
|
135 | 48 |
failAndError |
222 | 49 |
self assert: false. |
50 |
self assert: false. " second failure " |
|
51 |
self error. |
|
135 | 52 |
! |
53 |
||
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
54 |
noop |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
55 |
! |
0 | 56 |
|
57 |
setRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
58 |
hasRun := true |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
59 |
! ! |
0 | 60 |
|
68 | 61 |
!SUnitTest methodsFor:'running'! |
0 | 62 |
|
63 |
setUp |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
64 |
hasSetup := true |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
65 |
! ! |
0 | 66 |
|
68 | 67 |
!SUnitTest methodsFor:'testing'! |
0 | 68 |
|
109 | 69 |
errorShouldntRaise |
222 | 70 |
self |
71 |
shouldnt: [self someMessageThatIsntUnderstood] |
|
72 |
raise: SUnitNameResolver notificationObject |
|
109 | 73 |
! |
74 |
||
0 | 75 |
testAssert |
76 |
self assert: true. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
77 |
self deny: false |
0 | 78 |
! |
79 |
||
80 |
testDefects |
|
81 |
| result suite error failure | |
|
82 |
suite := TestSuite new. |
|
83 |
suite addTest: (error := self class selector: #error). |
|
84 |
suite addTest: (failure := self class selector: #fail). |
|
85 |
result := suite run. |
|
58 | 86 |
self assert: result defects asArray = (Array with: error with: failure). |
87 |
self |
|
88 |
assertForTestResult: result |
|
89 |
runCount: 2 |
|
90 |
passed: 0 |
|
91 |
failed: 1 |
|
92 |
errors: 1 |
|
0 | 93 |
! |
94 |
||
95 |
testDialectLocalizedException |
|
96 |
||
109 | 97 |
self |
98 |
should: [TestResult signalFailureWith: 'Foo'] |
|
99 |
raise: TestResult failure. |
|
100 |
self |
|
101 |
should: [TestResult signalErrorWith: 'Foo'] |
|
102 |
raise: TestResult error. |
|
0 | 103 |
! |
104 |
||
105 |
testError |
|
109 | 106 |
|
0 | 107 |
| case result | |
109 | 108 |
|
0 | 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 |
|
109 | 116 |
errors: 1. |
117 |
||
118 |
case := self class selector: #errorShouldntRaise. |
|
119 |
result := case run. |
|
222 | 120 |
self |
109 | 121 |
assertForTestResult: result |
122 |
runCount: 1 |
|
123 |
passed: 0 |
|
124 |
failed: 0 |
|
58 | 125 |
errors: 1 |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
126 |
! |
0 | 127 |
|
128 |
testException |
|
129 |
||
109 | 130 |
self |
131 |
should: [self error: 'foo'] |
|
132 |
raise: TestResult error |
|
0 | 133 |
! |
134 |
||
135 |
testFail |
|
109 | 136 |
|
0 | 137 |
| case result | |
109 | 138 |
|
0 | 139 |
case := self class selector: #fail. |
140 |
result := case run. |
|
109 | 141 |
|
58 | 142 |
self |
143 |
assertForTestResult: result |
|
144 |
runCount: 1 |
|
145 |
passed: 0 |
|
146 |
failed: 1 |
|
147 |
errors: 0 |
|
135 | 148 |
! |
149 |
||
0 | 150 |
testIsNotRerunOnDebug |
109 | 151 |
|
0 | 152 |
| case | |
109 | 153 |
|
0 | 154 |
case := self class selector: #testRanOnlyOnce. |
155 |
case run. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
156 |
case debug |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
157 |
! |
0 | 158 |
|
159 |
testRan |
|
109 | 160 |
|
0 | 161 |
| case | |
109 | 162 |
|
0 | 163 |
case := self class selector: #setRun. |
164 |
case run. |
|
165 |
self assert: case hasSetup. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
166 |
self assert: case hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
167 |
! |
0 | 168 |
|
169 |
testRanOnlyOnce |
|
109 | 170 |
|
0 | 171 |
self assert: hasRanOnce ~= true. |
109 | 172 |
hasRanOnce := true |
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
173 |
! |
0 | 174 |
|
175 |
testResult |
|
109 | 176 |
|
0 | 177 |
| case result | |
109 | 178 |
|
0 | 179 |
case := self class selector: #noop. |
180 |
result := case run. |
|
109 | 181 |
|
58 | 182 |
self |
183 |
assertForTestResult: result |
|
184 |
runCount: 1 |
|
185 |
passed: 1 |
|
186 |
failed: 0 |
|
187 |
errors: 0 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
188 |
! |
0 | 189 |
|
190 |
testRunning |
|
191 |
||
222 | 192 |
(SUnitDelay forSeconds: 2) wait |
0 | 193 |
! |
194 |
||
195 |
testShould |
|
109 | 196 |
|
197 |
self |
|
198 |
should: [true]; |
|
199 |
shouldnt: [false] |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
200 |
! |
0 | 201 |
|
202 |
testSuite |
|
109 | 203 |
|
0 | 204 |
| suite result | |
109 | 205 |
|
0 | 206 |
suite := TestSuite new. |
222 | 207 |
suite |
109 | 208 |
addTest: (self class selector: #noop); |
209 |
addTest: (self class selector: #fail); |
|
210 |
addTest: (self class selector: #error). |
|
211 |
||
0 | 212 |
result := suite run. |
109 | 213 |
|
58 | 214 |
self |
215 |
assertForTestResult: result |
|
216 |
runCount: 3 |
|
217 |
passed: 1 |
|
218 |
failed: 1 |
|
219 |
errors: 1 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
220 |
! ! |
0 | 221 |
|
14 | 222 |
!SUnitTest class methodsFor:'documentation'! |
223 |
||
224 |
version |
|
222 | 225 |
^ '$Header: /cvs/stx/stx/goodies/sunit/SUnitTest.st,v 1.11 2011-06-29 19:15:49 cg Exp $' |
226 |
! |
|
227 |
||
228 |
version_SVN |
|
229 |
^ '§Id: SUnitTest.st 214 2011-03-14 12:22:21Z vranyj1 §' |
|
14 | 230 |
! ! |