222
|
1 |
"{ Package: 'stx:goodies/sunit' }"
|
|
2 |
|
|
3 |
Object subclass:#TestResultReporter
|
|
4 |
instanceVariableNames:'result stream'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'SUnit-Report'
|
|
8 |
!
|
|
9 |
|
267
|
10 |
!TestResultReporter class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
public API entries are:
|
|
15 |
|aTestResult|
|
|
16 |
|
|
17 |
aTestResult := aUnitTest suite run.
|
|
18 |
TestResultReporter report:aTestResult format:#xml on: aStream
|
|
19 |
"
|
|
20 |
!
|
|
21 |
|
|
22 |
examples
|
|
23 |
"
|
|
24 |
|testResult|
|
|
25 |
|
|
26 |
testResult := RegressionTests::IntegerTest suite run.
|
|
27 |
TestResultReporter report:testResult format:#xml on:Transcript
|
|
28 |
"
|
|
29 |
! !
|
|
30 |
|
|
31 |
!TestResultReporter class methodsFor:'others'!
|
|
32 |
|
|
33 |
version_CVS
|
|
34 |
^ '$Id: TestResultReporter.st,v 1.2 2011-07-30 08:11:54 cg Exp $'
|
|
35 |
! !
|
222
|
36 |
|
|
37 |
!TestResultReporter class methodsFor:'reporting'!
|
|
38 |
|
|
39 |
report: aTestResult format: format as: stringOrFilename
|
|
40 |
|
|
41 |
self new report: aTestResult format: format as: stringOrFilename
|
|
42 |
!
|
|
43 |
|
|
44 |
report: aTestResult format: format on: stream
|
|
45 |
|
|
46 |
self new report: aTestResult format: format on: stream
|
267
|
47 |
|
|
48 |
"
|
|
49 |
self report:(RegressionTests::IntegerTest runTests) format:#xml on:Transcript
|
|
50 |
"
|
|
51 |
|
|
52 |
"Modified (comment): / 30-07-2011 / 09:37:53 / cg"
|
222
|
53 |
! !
|
|
54 |
|
|
55 |
!TestResultReporter methodsFor:'reporting'!
|
|
56 |
|
267
|
57 |
report:formatSymbol
|
|
58 |
"currently supported formatSymbols:
|
|
59 |
xml"
|
|
60 |
|
222
|
61 |
|reportFormatSelector|
|
|
62 |
|
267
|
63 |
reportFormatSelector := self reportFormatSelector:formatSymbol.
|
222
|
64 |
(self respondsTo: reportFormatSelector)
|
267
|
65 |
ifTrue:[self perform: reportFormatSelector]
|
|
66 |
ifFalse:[self error:'Unsupported format: ', formatSymbol].
|
|
67 |
|
|
68 |
"Modified (comment): / 30-07-2011 / 09:37:31 / cg"
|
222
|
69 |
!
|
|
70 |
|
|
71 |
report: aTestResult format: format as: stringOrFilename
|
|
72 |
|
|
73 |
| s |
|
|
74 |
s := stringOrFilename asFilename writeStream.
|
|
75 |
[ self report: aTestResult format: format on: s]
|
|
76 |
ensure:[s close].
|
|
77 |
!
|
|
78 |
|
|
79 |
report: aTestResult format: aSymbol on: aStream
|
|
80 |
|
|
81 |
result := aTestResult.
|
|
82 |
stream := aStream.
|
|
83 |
self report: aSymbol
|
|
84 |
!
|
|
85 |
|
|
86 |
reportFormatSelector:format
|
|
87 |
^ ('report' , format asString capitalized) asSymbol
|
|
88 |
! !
|
|
89 |
|
|
90 |
!TestResultReporter methodsFor:'reporting - xml'!
|
|
91 |
|
|
92 |
reportXml
|
267
|
93 |
"JUnit-like XML unittest report format"
|
222
|
94 |
|
|
95 |
stream
|
267
|
96 |
nextPutLine: '<?xml version="1.0"?>';
|
|
97 |
nextPutLine: '<unittest-results>'.
|
222
|
98 |
|
|
99 |
result passed do:[:each|self reportXmlTest: each result: #success].
|
|
100 |
result failures do:[:each|self reportXmlTest: each result: #failure].
|
|
101 |
result errors do:[:each|self reportXmlTest: each result: #error].
|
|
102 |
|
|
103 |
stream
|
267
|
104 |
nextPutLine: '</unittest-results>'
|
|
105 |
|
|
106 |
"Modified (format): / 30-07-2011 / 09:54:16 / cg"
|
222
|
107 |
!
|
|
108 |
|
|
109 |
reportXmlTest: test result: testResult
|
|
110 |
|
|
111 |
"
|
|
112 |
Example:
|
|
113 |
<test
|
267
|
114 |
duration='0.0188629627228'
|
|
115 |
status='error'
|
|
116 |
fixture='bitten.tests.web_ui.SourceFileLinkFormatterTestCase'
|
|
117 |
name='test_format_link_not_in_repos_with_line'
|
|
118 |
file='/usr/src/trac-bitten-0.6b2.dfsg/bitten/tests/web_ui.py'>
|
222
|
119 |
"
|
|
120 |
|
267
|
121 |
| testClassName executionTime |
|
|
122 |
|
222
|
123 |
testClassName := self sunitNameOf: test class.
|
|
124 |
|
267
|
125 |
"most tests do not know, and return nil here!!"
|
|
126 |
executionTime := test executionTime ? 0.0.
|
|
127 |
|
222
|
128 |
stream
|
267
|
129 |
nextPutAll:'<test duration="'; nextPutAll:executionTime; nextPutLine:'"';
|
|
130 |
tab; nextPutAll:'status="'; nextPutAll: testResult; nextPutLine:'"';
|
|
131 |
tab; nextPutAll:'ficture="'; nextPutAll: testClassName; nextPutLine:'"';
|
|
132 |
tab; nextPutAll:'name="'; nextPutAll: test selector; nextPutLine:'"';
|
|
133 |
"It seems that some tools requires the file attributes. So we supply one :-)"
|
|
134 |
tab; nextPutAll:'file="'; nextPutAll: testClassName , '.st'; nextPutLine:'">'.
|
222
|
135 |
|
|
136 |
testResult ~= #success ifTrue:[self reportXmlTraceback: test].
|
|
137 |
|
|
138 |
stream nextPutLine:'</test>'.
|
267
|
139 |
|
|
140 |
"Modified: / 30-07-2011 / 10:10:02 / cg"
|
222
|
141 |
!
|
|
142 |
|
|
143 |
reportXmlTraceback: test
|
|
144 |
|
|
145 |
"
|
|
146 |
Prints a traceback to the stream.
|
|
147 |
This is dialect-specific, so we have to check...
|
|
148 |
"
|
|
149 |
|
|
150 |
"Smalltalk/X dialect detection..."
|
|
151 |
((Smalltalk respondsTo: #isSmalltalkX) and:[Smalltalk isSmalltalkX])
|
|
152 |
ifTrue:[^self reportXmlTracebackStX: test]
|
|
153 |
!
|
|
154 |
|
|
155 |
reportXmlTracebackStX: test
|
|
156 |
|
|
157 |
stream nextPutLine:'<traceback><!![CDATA['.
|
|
158 |
|
|
159 |
[ test debug ]
|
|
160 |
on: GenericException
|
|
161 |
do: [:ex|
|
|
162 |
ex suspendedContext fullPrintAllOn: stream].
|
|
163 |
|
|
164 |
stream nextPutLine:']]></traceback>'.
|
|
165 |
|
|
166 |
"Modified: / 07-12-2009 / 14:06:48 / Jan Vrany <jan.vrant@fit.cvut.cz>"
|
|
167 |
! !
|
|
168 |
|
|
169 |
!TestResultReporter methodsFor:'utilities'!
|
|
170 |
|
|
171 |
sunitNameOf: aClass
|
|
172 |
|
|
173 |
"No all SUnit versions comes with sunitName
|
|
174 |
(at least Smalltalk/X 3.1)"
|
|
175 |
|
|
176 |
^(aClass respondsTo:#sunitName)
|
|
177 |
ifTrue:[aClass sunitName]
|
|
178 |
ifFalse:[aClass printString]
|
|
179 |
! !
|
|
180 |
|
|
181 |
!TestResultReporter class methodsFor:'documentation'!
|
|
182 |
|
|
183 |
version
|
267
|
184 |
^ '$Id: TestResultReporter.st,v 1.2 2011-07-30 08:11:54 cg Exp $'
|
222
|
185 |
!
|
|
186 |
|
|
187 |
version_SVN
|
|
188 |
^ '§Id§'
|
|
189 |
! !
|