author | vranyj1 |
Wed, 15 Jun 2011 08:47:24 +0000 | |
branch | jk_new_structure |
changeset 856 | dff0d4806336 |
parent 855 | 809b1dc41615 |
child 859 | 56bc5e063b7d |
permissions | -rw-r--r-- |
752 | 1 |
"{ Package: 'stx:libjava' }" |
2 |
||
3 |
TestCase subclass:#JUnitTestCaseProxy |
|
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'TestCases' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'Languages-Java-JUnit' |
|
8 |
! |
|
9 |
||
10 |
JUnitTestCaseProxy class instanceVariableNames:'javaClassName' |
|
11 |
||
12 |
" |
|
13 |
The following class instance variables are inherited by this class: |
|
14 |
||
15 |
TestCase - lastTestRunResultOrNil lastTestRunsPassedTests lastTestRunsFailedTests lastTestRunsErrorTests |
|
16 |
TestAsserter - |
|
17 |
Object - |
|
18 |
" |
|
19 |
! |
|
20 |
||
21 |
||
22 |
!JUnitTestCaseProxy class methodsFor:'initialization'! |
|
23 |
||
24 |
initialize |
|
25 |
||
26 |
TestCases := Dictionary new. |
|
27 |
||
28 |
"Created: / 01-03-2011 / 10:43:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
29 |
! |
|
30 |
||
31 |
setJavaClassName: aSymbol |
|
32 |
||
33 |
javaClassName ifNotNil: |
|
34 |
[self error: 'Attempting to set java class name twice']. |
|
35 |
javaClassName := aSymbol. |
|
36 |
||
37 |
"Created: / 01-03-2011 / 10:43:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
38 |
! ! |
|
39 |
||
40 |
!JUnitTestCaseProxy class methodsFor:'accessing'! |
|
41 |
||
42 |
javaClass |
|
43 |
||
44 |
^Java at: javaClassName |
|
45 |
||
46 |
"Created: / 01-03-2011 / 11:30:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
47 |
"Modified: / 01-03-2011 / 14:48:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
48 |
! |
|
49 |
||
50 |
javaClassName |
|
51 |
||
52 |
^javaClassName |
|
53 |
||
54 |
"Created: / 01-03-2011 / 11:30:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
55 |
! |
|
56 |
||
57 |
lookupHierarchyRoot |
|
58 |
||
59 |
^JUnitTestCaseProxy |
|
60 |
||
61 |
"Created: / 01-03-2011 / 11:41:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
62 |
"Modified: / 01-03-2011 / 14:54:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
63 |
! |
|
64 |
||
65 |
selector: aSymbol |
|
66 |
||
67 |
^super selector: aSymbol |
|
68 |
||
69 |
"Created: / 01-03-2011 / 11:55:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
70 |
! ! |
|
71 |
||
72 |
!JUnitTestCaseProxy class methodsFor:'private'! |
|
73 |
||
74 |
testSelectors |
|
75 |
| javaClass | |
|
76 |
||
77 |
self == JUnitTestCaseProxy ifTrue:[ ^ #() ]. |
|
78 |
javaClass := self javaClass. |
|
79 |
(javaClass includesBehavior:(JavaVM classForName:'junit.framework.TestCase')) |
|
80 |
ifTrue:[ ^ javaClass selectors select:[:sel | sel startsWith:'test' ]. ]. |
|
81 |
||
82 |
^ (javaClass |
|
83 |
selectMethodsAnnotatedWith:(JavaVM classForName:'org.junit.Test') typeName) |
|
84 |
collect:[:method | method selector ] |
|
85 |
||
86 |
" |
|
87 |
(JUnitTestCase for: JAVA::stx::libjava::tests::junit::JUnit3Tests) |
|
88 |
testSelectors" |
|
89 |
||
90 |
"Created: / 01-03-2011 / 10:49:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
91 |
"Modified: / 03-03-2011 / 00:34:39 / Marcel Hlopko <hlopik@gmail.com>" |
|
92 |
"Modified: / 04-03-2011 / 00:05:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
93 |
! ! |
|
94 |
||
95 |
!JUnitTestCaseProxy class methodsFor:'queries'! |
|
96 |
||
97 |
isAbstract |
|
98 |
||
99 |
^self == JUnitTestCaseProxy |
|
100 |
||
101 |
"Created: / 28-02-2011 / 22:32:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
102 |
"Modified: / 01-03-2011 / 14:54:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
854
e165b3da9adb
Fixes for running tests in separate processes (required since VM often crash)
vranyj1
parents:
752
diff
changeset
|
103 |
|
e165b3da9adb
Fixes for running tests in separate processes (required since VM often crash)
vranyj1
parents:
752
diff
changeset
|
104 |
! |
e165b3da9adb
Fixes for running tests in separate processes (required since VM often crash)
vranyj1
parents:
752
diff
changeset
|
105 |
|
e165b3da9adb
Fixes for running tests in separate processes (required since VM often crash)
vranyj1
parents:
752
diff
changeset
|
106 |
shouldFork |
e165b3da9adb
Fixes for running tests in separate processes (required since VM often crash)
vranyj1
parents:
752
diff
changeset
|
107 |
|
e165b3da9adb
Fixes for running tests in separate processes (required since VM often crash)
vranyj1
parents:
752
diff
changeset
|
108 |
^true |
e165b3da9adb
Fixes for running tests in separate processes (required since VM often crash)
vranyj1
parents:
752
diff
changeset
|
109 |
|
752 | 110 |
! ! |
111 |
||
112 |
!JUnitTestCaseProxy class methodsFor:'subclass creation'! |
|
113 |
||
114 |
for:javaClass |
|
115 |
"Answers a new (anonymous) testcase proxy for |
|
116 |
given javaClass" |
|
117 |
||
118 |
| meta cls name | |
|
119 |
||
120 |
self assert:javaClass isJavaClass description:'Not a java class'. |
|
121 |
self assert:javaClass isTestCaseLike |
|
122 |
description:'Not a testcase-like class'. |
|
123 |
name := javaClass name. |
|
124 |
TestCases at: name ifPresent:[:c|^c]. |
|
125 |
||
126 |
meta := Metaclass new. |
|
127 |
meta setSuperclass: JUnitTestCaseProxy class. |
|
128 |
meta instSize: JUnitTestCaseProxy class instSize. |
|
129 |
cls := meta new. |
|
130 |
cls setSuperclass: JUnitTestCaseProxy. |
|
131 |
cls flags: JUnitTestCaseProxy flags. |
|
132 |
cls instSize: JUnitTestCaseProxy instSize. |
|
133 |
cls setJavaClassName: name. |
|
134 |
cls setName: ('JUnitTestCase for: (Java classForName: ', name storeString, ')') asSymbol. |
|
135 |
cls setCategory: javaClass category. |
|
136 |
TestCases at: name put: cls. |
|
137 |
^cls |
|
138 |
||
139 |
"Created: / 01-03-2011 / 10:30:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
140 |
"Modified: / 03-03-2011 / 00:20:49 / Marcel Hlopko <hlopik@gmail.com>" |
|
141 |
"Modified: / 01-04-2011 / 16:02:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
142 |
! ! |
|
143 |
||
144 |
!JUnitTestCaseProxy methodsFor:'accessing'! |
|
145 |
||
146 |
javaClass |
|
147 |
||
148 |
| javaClass | |
|
149 |
||
150 |
self |
|
151 |
assert: (javaClass := self class javaClass) isJavaClass |
|
152 |
description: 'java class does not exists'. |
|
153 |
^javaClass |
|
154 |
||
155 |
"Created: / 01-03-2011 / 14:48:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
855
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
156 |
|
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
157 |
! |
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
158 |
|
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
159 |
nameForHDTestReport |
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
160 |
|
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
161 |
^self class javaClassName copyReplaceAll:$/ with: $. |
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
162 |
|
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
163 |
"Created: / 01-04-2011 / 16:10:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
164 |
|
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
165 |
! |
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
166 |
|
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
167 |
selectorForHDTestReport |
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
168 |
|
856 | 169 |
^testSelector upTo:$( |
855
809b1dc41615
use nameForHDTestReport and selectorForHDTestReport to identify test
vranyj1
parents:
854
diff
changeset
|
170 |
|
752 | 171 |
! ! |
172 |
||
173 |
!JUnitTestCaseProxy methodsFor:'private'! |
|
174 |
||
175 |
performTest |
|
176 |
||
177 |
<resource: #skipInDebuggersWalkBack> |
|
178 |
||
179 |
[ |
|
180 |
self javaClass new perform: testSelector sunitAsSymbol |
|
181 |
] on: JavaError do: [:ex| |
|
182 |
"This is the tricky part. We have to auto-magically convert |
|
183 |
jUnit's AssertionFailedError to sUnits TestFailure's" |
|
184 |
||
185 |
"Bad, bad, I know..." |
|
186 |
(ex parameter class name == #'junit/framework/AssertionFailedError') |
|
187 |
ifTrue: |
|
188 |
[ TestResult failure sunitSignalWith: ex description ] |
|
189 |
ifFalse: |
|
190 |
[ ex pass ] |
|
191 |
] |
|
192 |
||
193 |
"Created: / 01-03-2011 / 14:50:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
194 |
"Modified: / 04-03-2011 / 00:07:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
195 |
! ! |
|
196 |
||
197 |
!JUnitTestCaseProxy class methodsFor:'documentation'! |
|
198 |
||
199 |
version_SVN |
|
200 |
^ '$Id$' |
|
201 |
! ! |
|
202 |
||
203 |
JUnitTestCaseProxy initialize! |