0
|
1 |
'From Smalltalk/X, Version:4.1.1 on 24-oct-2000 at 08:10:32 pm' !
|
|
2 |
|
|
3 |
"{ Package: 'stx:goodies/sunit' }"
|
|
4 |
|
|
5 |
Object subclass:#TestCase
|
|
6 |
instanceVariableNames:'testSelector'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'SUnit'
|
|
10 |
!
|
|
11 |
|
|
12 |
!TestCase class methodsFor:'Instance Creation'!
|
|
13 |
|
|
14 |
debug: aSymbol
|
|
15 |
^(self selector: aSymbol) debug!
|
|
16 |
|
|
17 |
run: aSymbol
|
|
18 |
^(self selector: aSymbol) run!
|
|
19 |
|
|
20 |
selector: aSymbol
|
|
21 |
^self new setTestSelector: aSymbol!
|
|
22 |
|
|
23 |
suite
|
|
24 |
| testSelectors result |
|
|
25 |
testSelectors := self sunitSelectors select: [:each | 'test*' sunitMatch: each].
|
|
26 |
result := TestSuite new.
|
|
27 |
testSelectors do: [:each | result addTest: (self selector: each)].
|
|
28 |
^result
|
|
29 |
|
|
30 |
"Modified: / 21.6.2000 / 10:05:24 / Sames"
|
|
31 |
! !
|
|
32 |
|
|
33 |
!TestCase methodsFor:'Accessing'!
|
|
34 |
|
|
35 |
assert: aBoolean
|
|
36 |
aBoolean ifFalse: [self signalFailure: 'Assertion failed']
|
|
37 |
|
|
38 |
"Modified: / 21.6.2000 / 10:00:05 / Sames"
|
|
39 |
!
|
|
40 |
|
|
41 |
deny: aBoolean
|
|
42 |
self assert: aBoolean not!
|
|
43 |
|
|
44 |
should: aBlock
|
|
45 |
self assert: aBlock value!
|
|
46 |
|
|
47 |
should: aBlock raise: anExceptionalEvent
|
|
48 |
^self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent)
|
|
49 |
|
|
50 |
"Modified: / 21.6.2000 / 10:01:08 / Sames"
|
|
51 |
!
|
|
52 |
|
|
53 |
shouldnt: aBlock
|
|
54 |
self deny: aBlock value!
|
|
55 |
|
|
56 |
shouldnt: aBlock raise: anExceptionalEvent
|
|
57 |
^self assert: (self executeShould: aBlock inScopeOf: anExceptionalEvent) not
|
|
58 |
|
|
59 |
"Modified: / 21.6.2000 / 10:01:16 / Sames"
|
|
60 |
!
|
|
61 |
|
|
62 |
signalFailure: aString
|
|
63 |
TestResult failure sunitSignalWith: aString
|
|
64 |
|
|
65 |
"Modified: / 21.6.2000 / 10:01:34 / Sames"
|
|
66 |
! !
|
|
67 |
|
|
68 |
!TestCase methodsFor:'Dependencies'!
|
|
69 |
|
|
70 |
addDependentToHierachy: anObject
|
|
71 |
"an empty method. for Composite compability with TestSuite"!
|
|
72 |
|
|
73 |
removeDependentFromHierachy: anObject
|
|
74 |
"an empty method. for Composite compability with TestSuite"! !
|
|
75 |
|
|
76 |
!TestCase methodsFor:'Printing'!
|
|
77 |
|
|
78 |
printOn: aStream
|
|
79 |
aStream nextPutAll: self class name.
|
|
80 |
aStream nextPutAll: '>>'.
|
|
81 |
aStream nextPutAll: testSelector
|
|
82 |
|
|
83 |
"Modified: / 4.4.2000 / 18:59:53 / Sames"
|
|
84 |
! !
|
|
85 |
|
|
86 |
!TestCase methodsFor:'Private'!
|
|
87 |
|
|
88 |
executeShould: aBlock inScopeOf: anExceptionalEvent
|
|
89 |
[[aBlock value]
|
|
90 |
sunitOn: anExceptionalEvent
|
|
91 |
do: [:ex | ^true]]
|
|
92 |
sunitOn: TestResult error
|
|
93 |
do: [:ex | ^false].
|
|
94 |
^false.
|
|
95 |
|
|
96 |
"Modified: / 21.6.2000 / 10:03:03 / Sames"
|
|
97 |
!
|
|
98 |
|
|
99 |
setTestSelector: aSymbol
|
|
100 |
testSelector := aSymbol! !
|
|
101 |
|
|
102 |
!TestCase methodsFor:'Running'!
|
|
103 |
|
|
104 |
debug
|
|
105 |
(self class selector: testSelector) runCase!
|
|
106 |
|
|
107 |
debugAsFailure
|
|
108 |
(self class selector: testSelector) runCaseAsFailure!
|
|
109 |
|
|
110 |
openDebuggerOnFailingTestMethod
|
|
111 |
"SUnit has halted one step in front of the failing test method.
|
|
112 |
Step over the 'self halt' and send into 'self perform: testSelector'
|
|
113 |
to see the failure from the beginning"
|
|
114 |
|
|
115 |
self halt.
|
|
116 |
self perform: testSelector sunitAsSymbol
|
|
117 |
|
|
118 |
"Modified: / 21.6.2000 / 10:03:37 / Sames"
|
|
119 |
!
|
|
120 |
|
|
121 |
run
|
|
122 |
| result |
|
|
123 |
result := TestResult new.
|
|
124 |
self run: result.
|
|
125 |
^result!
|
|
126 |
|
|
127 |
run: aResult
|
|
128 |
aResult runCase: self!
|
|
129 |
|
|
130 |
runCase
|
|
131 |
self setUp.
|
|
132 |
[self perform: testSelector sunitAsSymbol] sunitEnsure: [self tearDown]
|
|
133 |
|
|
134 |
"Modified: / 21.6.2000 / 10:04:18 / Sames"
|
|
135 |
!
|
|
136 |
|
|
137 |
runCaseAsFailure
|
|
138 |
self setUp.
|
|
139 |
[[self openDebuggerOnFailingTestMethod] sunitEnsure: [self tearDown]] fork
|
|
140 |
|
|
141 |
"Modified: / 21.6.2000 / 10:04:33 / Sames"
|
|
142 |
!
|
|
143 |
|
|
144 |
setUp!
|
|
145 |
|
|
146 |
tearDown! !
|
|
147 |
|