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