When running SUnit tests, capture and log stdout, stderr and Transcript and include it in XML report.
--- a/reports/Builder__TestReportFormat.st Tue May 27 18:06:15 2014 +0200
+++ b/reports/Builder__TestReportFormat.st Fri Jun 06 02:23:26 2014 +0200
@@ -81,15 +81,16 @@
"Write an outcome of a given test.
Argumments:
- testcase....the testcase
- outcome.....one of #pass, #failure, #error
+ testcase....the testcase <TestCase>
+ outcome.....the testcase outcome <TestCaseOutcome>
time........time taken to run the test in milliseconds
- exception...exception that caused error/failure or nil if N/A
- backtrace...stacktrace info or nil if N/A"
+ exception...exception that caused error/failure or nil if N/A < Exception | nil >
+ backtrace...stacktrace info or nil if N/A <String | nil >"
self subclassResponsibility
"Created: / 03-08-2011 / 19:43:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 06-06-2014 / 00:51:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TestReportFormat methodsFor:'writing - utilities'!
@@ -245,22 +246,57 @@
nextPutAll:(Report encode:report name);
nextPutAll:'" tests="';
print:report suite testCount;
- nextPutAll:'">'.
+ nextPutAll:('" hostname="%1"' bindWith:OperatingSystem getHostName);
+ nextPutAll:'>'.
"Now this is ugly. We want to update the time and the number of failures and errors, but still at the same time stream a valid XML. So remember this position and add some whitespace, that we can fill later."
position := stream stream position - 1.
stream
nextPutAll:(String new:100 withAll:$ );
nextPut:Character lf.
+ stream
+ nextPutLine: ' <properties>';
+ nextPutLine: ' <property name="programmingLanguage" value="Smalltalk" />';
+ nextPutLine: ' <property name="smalltalk.vendor" value="exept Software AG" />';
+ nextPutLine: ' <property name="smalltalk.compiler" value="Smalltalk/X" />';
+ nextPutLine:(' <property name="smalltalk.version" value="%1" />'bindWith:Smalltalk versionString);
+ nextPutLine:(' <property name="os.name" value="%1" />' bindWith:OperatingSystem osName);
+ nextPutLine:(' <property name="os.arch" value="%1" />' bindWith:OperatingSystem getCPUType);
+ nextPutLine:(' <property name="user.name" value="%1" />' bindWith:OperatingSystem getLoginName);
+ nextPutLine:(' <property name="user.language" value="%1" />' bindWith:Smalltalk language).
+"/ stream
+"/ nextPutLine:(' <property name="smalltalk.libbasic.version" value="%1" />'bindWith:stx_libbasic versionString).
+ stream
+ nextPutLine: ' </properties>'.
+
startTime := OperatingSystem getMillisecondTime.
"Created: / 03-08-2011 / 19:14:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 06-06-2014 / 01:14:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
writeTestCase:testcase outcome:outcome time:time exception: exception stacktrace:stacktrace
+ | result |
- outcome == #failure ifTrue:[failures := failures + 1].
- outcome == #error ifTrue:[errors := errors + 1].
- outcome == #skip ifTrue:[skipped := skipped + 1].
+ outcome result == TestResult statePass ifTrue:[
+ result := #pass.
+ ] ifFalse:[
+ outcome result == TestResult stateFail ifTrue:[
+ result := #failure.
+ failures := failures + 1
+ ] ifFalse:[
+ outcome result == TestResult stateError ifTrue:[
+ result := #error.
+ errors := errors + 1.
+ ] ifFalse:[
+ outcome result == TestResult stateSkip ifTrue:[
+ result := #skip.
+ skipped := skipped + 1
+ ] ifFalse:[
+ self error: 'Invalid test result'.
+ ]
+ ].
+ ].
+ ].
stream tab;
nextPutAll: '<testcase classname="';
@@ -269,10 +305,10 @@
nextPutAll: (self encode: testcase selectorForHDTestReport);
nextPutAll: '" time="'; print: (time ? 0) / 1000.0; nextPutAll: '">'; cr.
- outcome == #skip ifTrue:[
+ result == #skip ifTrue:[
stream tab; tab; nextPutAll: '<skipped/>'.
] ifFalse:[
- outcome ~~ #pass ifTrue:[
+ result ~~ #pass ifTrue:[
| type message |
exception isNil ifTrue:[
@@ -285,7 +321,7 @@
stream tab; tab;
- nextPut:$<; nextPutAll: outcome;
+ nextPut:$<; nextPutAll: result;
nextPutAll:' type="';
nextPutAll:(self encode:type);
nextPutAll:'" message="';
@@ -293,10 +329,15 @@
nextPutAll:'"><!![CDATA['; cr.
self writeCDATA: (stacktrace ? 'stacktrace not available').
stream
- nextPutAll:']]></'; nextPutAll: outcome; nextPutAll:'>';
+ nextPutAll:']]></'; nextPutAll: result; nextPutAll:'>';
nextPut:Character lf
].
].
+ outcome collectedOutput notEmptyOrNil ifTrue:[
+ stream nextPutAll:' <system-out><!![CDATA['; cr.
+ self writeCDATA: outcome collectedOutput.
+ stream nextPutAll:']]> </system-out>'; cr.
+ ].
stream tab;
nextPutAll: '</testcase>'; cr.
@@ -305,7 +346,7 @@
stream flush
"Created: / 03-08-2011 / 19:42:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 05-07-2013 / 16:54:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 06-06-2014 / 01:03:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TestReportFormat::JUnit methodsFor:'writing - utilities'!
@@ -414,8 +455,8 @@
executionTime := time. "/ millis
testDescription := '%1-%2' bindWith:testClassName with:testName.
- successPassed := (outcome == #pass) ifTrue:['yes'] ifFalse:['no'].
- outcome ~~ #pass ifTrue:[
+ successPassed := (outcome result == TestResult statePass) ifTrue:['yes'] ifFalse:['no'].
+ (outcome result ~~ TestResult statePass) ifTrue:[
exceptionInfo := stacktrace ? 'No stacktrace available'.
].
@@ -474,7 +515,7 @@
stream nextPutLine:'</test>'.
- "Modified: / 03-08-2011 / 20:15:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 06-06-2014 / 00:47:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TestReportFormat::PythonUnittest class methodsFor:'accessing'!
@@ -524,15 +565,31 @@
file='/usr/src/trac-bitten-0.6b2.dfsg/bitten/tests/web_ui.py'>
"
- | testClassName status |
+ | testClassName result |
testClassName := testcase class printString.
- status := outcome == #pass ifTrue:[#success] ifFalse:[outcome].
+ outcome result == TestResult statePass ifTrue:[
+ result := #success.
+ ] ifFalse:[
+ outcome result == TestResult stateFail ifTrue:[
+ result := #failure.
+ ] ifFalse:[
+ outcome result == TestResult stateError ifTrue:[
+ result := #error.
+ ] ifFalse:[
+ outcome result == TestResult stateSkip ifTrue:[
+ result := #skip.
+ ] ifFalse:[
+ self error: 'Invalid test result'.
+ ]
+ ].
+ ].
+ ].
stream
nextPutAll:'<test duration="'; nextPutAll:time; nextPutLine:'"';
- tab; nextPutAll:'status="'; nextPutAll: status; nextPutLine:'"';
+ tab; nextPutAll:'status="'; nextPutAll: result; nextPutLine:'"';
tab; nextPutAll:'ficture="'; nextPutAll: testClassName; nextPutLine:'"';
tab; nextPutAll:'name="'; nextPutAll: testcase selector; nextPutLine:'"';
"It seems that some tools requires the file attributes. So we supply one :-)"
@@ -546,7 +603,7 @@
stream nextPutLine:'</test>'.
- "Modified: / 03-08-2011 / 20:23:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 06-06-2014 / 00:50:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TestReportFormat::TAP class methodsFor:'accessing'!
@@ -594,16 +651,33 @@
writeTestCase:testcase outcome:outcome time:time exception:exception stacktrace:stacktrace
- | testDescription statusString|
+ | result testDescription statusString |
index := index + 1.
+ outcome result == TestResult statePass ifTrue:[
+ result := #pass.
+ ] ifFalse:[
+ outcome result == TestResult stateFail ifTrue:[
+ result := #failure.
+ ] ifFalse:[
+ outcome result == TestResult stateError ifTrue:[
+ result := #error.
+ ] ifFalse:[
+ outcome result == TestResult stateSkip ifTrue:[
+ result := #skip.
+ ] ifFalse:[
+ self error: 'Invalid test result'.
+ ]
+ ].
+ ].
+ ].
testDescription := '%1-%2 (%3ms)'
bindWith:testcase printString
with:testcase selector
with:time.
- statusString := (outcome == #pass)
+ statusString := (result == #pass)
ifTrue:['ok']
ifFalse:['not ok'].
@@ -612,7 +686,7 @@
with:index
with:testDescription).
- "Modified: / 03-08-2011 / 20:08:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 06-06-2014 / 00:46:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!TestReportFormat class methodsFor:'documentation'!