author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 09 Jul 2014 23:00:04 +0100 | |
branch | working_v5_0 |
changeset 613 | 5a546630cfcf |
parent 612 | ef24164cb298 |
permissions | -rw-r--r-- |
108 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
TestCase subclass:#SimpleTestResourceTestCase |
|
4 |
instanceVariableNames:'resource' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'SUnit-Tests' |
|
8 |
! |
|
9 |
||
10 |
||
222 | 11 |
!SimpleTestResourceTestCase class methodsFor:'accessing'! |
108 | 12 |
|
13 |
resources |
|
222 | 14 |
^Array with: SimpleTestResource |
108 | 15 |
! ! |
16 |
||
17 |
!SimpleTestResourceTestCase methodsFor:'Not categorized'! |
|
18 |
||
19 |
testRan |
|
20 |
| case | |
|
21 |
||
22 |
case := self class selector: #setRun. |
|
23 |
case run. |
|
24 |
self assert: resource hasSetup. |
|
25 |
self assert: resource hasRun |
|
222 | 26 |
|
108 | 27 |
! |
28 |
||
29 |
testResourceInitRelease |
|
30 |
| result suite error failure | |
|
31 |
suite := TestSuite new. |
|
32 |
suite addTest: (error := self class selector: #error). |
|
33 |
suite addTest: (failure := self class selector: #fail). |
|
34 |
suite addTest: (self class selector: #dummy). |
|
35 |
result := suite run. |
|
36 |
self assert: resource hasSetup |
|
37 |
||
38 |
! ! |
|
39 |
||
222 | 40 |
!SimpleTestResourceTestCase methodsFor:'private'! |
108 | 41 |
|
222 | 42 |
dummy |
43 |
self assert: resource hasSetup |
|
44 |
description: 'This test uses a resource but it was not set up'. |
|
45 |
self setRun. |
|
46 |
self assert: resource hasRun |
|
47 |
description: 'This test uses a resource but we could not interact with it'. |
|
108 | 48 |
! |
49 |
||
222 | 50 |
error |
51 |
'foo' odd |
|
52 |
! |
|
108 | 53 |
|
222 | 54 |
fail |
55 |
self assert: false |
|
56 |
! |
|
57 |
||
58 |
setRun |
|
59 |
resource setRun |
|
108 | 60 |
! ! |
61 |
||
222 | 62 |
!SimpleTestResourceTestCase methodsFor:'running'! |
108 | 63 |
|
64 |
setUp |
|
222 | 65 |
"Ensure that we error, not just fail, if resource is nil so that #should:raise: checks cannot mistake such an error for what they are trapping." |
66 |
||
67 |
resource := SimpleTestResource rawCurrentForTest. |
|
68 |
self deny: resource isNil |
|
69 |
description: 'SimpleTestResource has no current value in test'. |
|
70 |
self assert: resource class == SimpleTestResource |
|
71 |
description: 'SimpleTestResource current is not an instance of itself'. |
|
72 |
self assert: resource hasSetup |
|
73 |
description: 'This test uses a resource but it was not set up'. |
|
108 | 74 |
! |
75 |
||
222 | 76 |
testDebugTestWithResource |
77 |
"The debug will raise an error if the resource is not set up properly." |
|
108 | 78 |
|
222 | 79 |
self clearOuterResourceStateDuring: |
80 |
[(self class selector: #setRun) debug]. |
|
108 | 81 |
! |
82 |
||
222 | 83 |
testResourceCollection |
84 |
self assert: self class buildSuiteFromSelectors resources size = self resources size |
|
85 |
description: 'The suite should have the same number of resources as its test'. |
|
86 |
self class buildSuiteFromSelectors resources do: |
|
87 |
[:each | |
|
88 |
self assert: (self resources includes: each) |
|
89 |
description: each name, ': I have this resource but my suite does not']. |
|
108 | 90 |
! |
91 |
||
222 | 92 |
testRunSuiteWithResource |
612
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
93 |
| suite | |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
94 |
suite := TestSuite new. |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
95 |
suite addTest: (SimpleTestResourceTestCase selector: #error). |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
96 |
suite addTest: (SimpleTestResourceTestCase selector: #fail). |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
97 |
suite addTest: (self class selector: #dummy). |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
98 |
self clearOuterResourceStateDuring: |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
99 |
[self assert: suite run printString = '3 run, 1 passed, 0 skipped, 1 failed, 1 error' |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
100 |
description: 'A suite of tests needing SimpleTestResource did not run as expected']. |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
101 |
|
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
102 |
"Modified: / 09-07-2014 / 21:36:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
222 | 103 |
! |
108 | 104 |
|
222 | 105 |
testRunTestWithResource |
612
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
106 |
self clearOuterResourceStateDuring: |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
107 |
[self assert: (self class selector: #dummy) run printString |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
108 |
= '1 run, 1 passed, 0 skipped, 0 failed, 0 errors' |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
109 |
description: 'A dummy test that needed a resource did not pass']. |
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
110 |
|
ef24164cb298
Fix tests that assert's TestResult printString.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
611
diff
changeset
|
111 |
"Modified: / 09-07-2014 / 21:36:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
108 | 112 |
! ! |
113 |
||
222 | 114 |
!SimpleTestResourceTestCase methodsFor:'utility'! |
108 | 115 |
|
222 | 116 |
clearOuterResourceStateDuring: aBlock |
117 |
"This self-testing test must clear the outer state of its resources before starting and after finishing, so that it can construct test cases and suites of itself and test them." |
|
108 | 118 |
|
222 | 119 |
self assert: SimpleTestResource isAlreadyAvailable |
120 |
description: 'The resource was not set up for the test'. |
|
121 |
SimpleTestResource reset. |
|
122 |
self deny: SimpleTestResource isAlreadyAvailable |
|
123 |
description: 'The resource was still set up before we began the run'. |
|
124 |
^aBlock sunitEnsure: |
|
125 |
[self deny: SimpleTestResource isAlreadyAvailable |
|
126 |
description: 'The resource was still set up after we finished the run'. |
|
127 |
SimpleTestResource isAvailable. |
|
128 |
self assert: SimpleTestResource isAlreadyAvailable |
|
129 |
description: 'The resource was not set up again after the test']. |
|
108 | 130 |
! ! |
131 |
||
132 |
!SimpleTestResourceTestCase class methodsFor:'documentation'! |
|
133 |
||
134 |
version |
|
222 | 135 |
^ '$Header: /cvs/stx/stx/goodies/sunit/SimpleTestResourceTestCase.st,v 1.2 2011-06-29 19:15:49 cg Exp $' |
136 |
! |
|
137 |
||
138 |
version_SVN |
|
139 |
^ '§Id: SimpleTestResourceTestCase.st 214 2011-03-14 12:22:21Z vranyj1 §' |
|
108 | 140 |
! ! |
611
1eecc860f4a5
Project definition fixed and HG configured as for CVS mirror repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
222
diff
changeset
|
141 |