author | Claus Gittinger <cg@exept.de> |
Thu, 13 Dec 2001 23:50:27 +0100 | |
changeset 52 | e107aeb7b5b7 |
parent 41 | 9828e423824b |
child 58 | 6fc01534c854 |
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 |
||
0 | 17 |
!SUnitTest methodsFor:'Accessing'! |
18 |
||
19 |
hasRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
20 |
^hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
21 |
! |
0 | 22 |
|
23 |
hasSetup |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
24 |
^hasSetup |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
25 |
! ! |
0 | 26 |
|
27 |
!SUnitTest methodsFor:'Private'! |
|
28 |
||
29 |
error |
|
30 |
3 zork |
|
31 |
||
32 |
"Modified: / 21.6.2000 / 10:22:18 / Sames" |
|
33 |
! |
|
34 |
||
35 |
fail |
|
52 | 36 |
"force a failure" |
37 |
self assert: false |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
38 |
! |
0 | 39 |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
40 |
noop |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
41 |
! |
0 | 42 |
|
43 |
setRun |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
44 |
hasRun := true |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
45 |
! ! |
0 | 46 |
|
47 |
!SUnitTest methodsFor:'Running'! |
|
48 |
||
49 |
setUp |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
50 |
hasSetup := true |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
51 |
! ! |
0 | 52 |
|
53 |
!SUnitTest methodsFor:'Testing'! |
|
54 |
||
55 |
testAssert |
|
56 |
self assert: true. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
57 |
self deny: false |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
58 |
! |
0 | 59 |
|
60 |
testDebugUI |
|
61 |
"This should break" |
|
62 |
3 zork |
|
63 |
||
64 |
"Modified: / 21.6.2000 / 10:22:50 / Sames" |
|
65 |
! |
|
66 |
||
67 |
testDefects |
|
68 |
| result suite error failure | |
|
69 |
suite := TestSuite new. |
|
70 |
suite addTest: (error := self class selector: #error). |
|
71 |
suite addTest: (failure := self class selector: #fail). |
|
72 |
result := suite run. |
|
73 |
self assert: result defects asArray = (Array with: error with: failure) |
|
74 |
||
75 |
"Modified: / 21.6.2000 / 10:23:04 / Sames" |
|
76 |
! |
|
77 |
||
78 |
testDialectLocalizedException |
|
79 |
self should: [TestResult signalFailureWith: 'Foo'] raise: TestResult failure. |
|
80 |
self should: [TestResult signalErrorWith: 'Foo'] raise: TestResult error. |
|
81 |
self shouldnt: [TestResult signalErrorWith: 'Foo'] raise: TestResult failure. |
|
82 |
||
83 |
"Modified: / 21.6.2000 / 10:23:20 / Sames" |
|
84 |
! |
|
85 |
||
86 |
testError |
|
87 |
| case result | |
|
88 |
case := self class selector: #error. |
|
89 |
result := case run. |
|
90 |
self assert: result correctCount = 0. |
|
91 |
self assert: result failureCount = 0. |
|
92 |
self assert: result runCount = 1. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
93 |
self assert: result errorCount = 1 |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
94 |
! |
0 | 95 |
|
96 |
testException |
|
97 |
self should: [self error: 'foo'] raise: TestResult error |
|
98 |
||
99 |
"Modified: / 21.6.2000 / 10:23:39 / Sames" |
|
100 |
! |
|
101 |
||
102 |
testFail |
|
103 |
| case result | |
|
104 |
case := self class selector: #fail. |
|
105 |
result := case run. |
|
106 |
self assert: result correctCount = 0. |
|
107 |
self assert: result failureCount = 1. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
108 |
self assert: result runCount = 1 |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
109 |
! |
0 | 110 |
|
111 |
testFailureDebugUI |
|
112 |
"This should fail !!" |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
113 |
self fail |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
114 |
! |
0 | 115 |
|
116 |
testIsNotRerunOnDebug |
|
117 |
| case | |
|
118 |
case := self class selector: #testRanOnlyOnce. |
|
119 |
case run. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
120 |
case debug |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
121 |
! |
0 | 122 |
|
123 |
testRan |
|
124 |
| case | |
|
125 |
case := self class selector: #setRun. |
|
126 |
case run. |
|
127 |
self assert: case hasSetup. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
128 |
self assert: case hasRun |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
129 |
! |
0 | 130 |
|
131 |
testRanOnlyOnce |
|
132 |
self assert: hasRanOnce ~= true. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
133 |
hasRanOnce := true. |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
134 |
! |
0 | 135 |
|
136 |
testResult |
|
137 |
| case result | |
|
138 |
case := self class selector: #noop. |
|
139 |
result := case run. |
|
140 |
self assert: result runCount = 1. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
141 |
self assert: result correctCount = 1 |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
142 |
! |
0 | 143 |
|
144 |
testRunning |
|
145 |
(SUnitDelay forSeconds: 2) wait |
|
146 |
||
147 |
"Modified: / 21.6.2000 / 10:24:41 / Sames" |
|
148 |
! |
|
149 |
||
150 |
testShould |
|
151 |
self should: [true]. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
152 |
self shouldnt: [false] |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
153 |
! |
0 | 154 |
|
155 |
testSuite |
|
156 |
| suite result | |
|
157 |
suite := TestSuite new. |
|
158 |
suite addTest: (self class selector: #noop). |
|
159 |
suite addTest: (self class selector: #fail). |
|
160 |
result := suite run. |
|
161 |
self assert: result runCount = 2. |
|
162 |
self assert: result correctCount = 1. |
|
6
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
163 |
self assert: result failureCount = 1 |
78bb1397e43d
added rerun-defect tests; fixed button enable bug
Claus Gittinger <cg@exept.de>
parents:
0
diff
changeset
|
164 |
! ! |
0 | 165 |
|
14 | 166 |
!SUnitTest class methodsFor:'documentation'! |
167 |
||
168 |
version |
|
52 | 169 |
^ '$Header: /cvs/stx/stx/goodies/sunit/SUnitTest.st,v 1.6 2001-12-13 22:50:27 cg Exp $' |
14 | 170 |
! ! |