junit: Include output in JUnit report for successful tests and benchmarks

This commit is contained in:
Joël Stemmer 2022-04-01 20:41:31 +01:00
parent a4c479dbbb
commit d2592490b6
12 changed files with 196 additions and 24 deletions

View File

@ -178,6 +178,8 @@ func CreateFromReport(report gtr.Report, hostname string) Testsuites {
Message: "No test result found",
Data: formatOutput(test.Output, test.Level),
}
} else if len(test.Output) > 0 {
tc.SystemOut = &Output{Data: formatOutput(test.Output, test.Level)}
}
suite.AddTestcase(tc)
@ -198,6 +200,8 @@ func CreateFromReport(report gtr.Report, hostname string) Testsuites {
tc.Skipped = &Result{
Message: "Skipped",
}
} else if len(bm.Output) > 0 {
tc.SystemOut = &Output{Data: formatOutput(bm.Output, 0)}
}
suite.AddTestcase(tc)

View File

@ -5,7 +5,12 @@
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="TestPass" classname="package/pass" time="0.060"></testcase>
<testcase name="TestPassLog" classname="package/pass" time="0.100"></testcase>
<testcase name="TestPassLog" classname="package/pass" time="0.100">
<system-out><![CDATA[ pass_test.go:9: log line
pass_test.go:10: log
multi
line]]></system-out>
</testcase>
</testsuite>
<testsuite name="package/fail" tests="1" failures="1" errors="0" hostname="hostname" time="0.151" timestamp="2022-01-01T00:00:00Z">
<properties>

View File

@ -4,6 +4,11 @@
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="TestPass" classname="package/pass" time="0.060"></testcase>
<testcase name="TestPassLog" classname="package/pass" time="0.100"></testcase>
<testcase name="TestPassLog" classname="package/pass" time="0.100">
<system-out><![CDATA[ pass_test.go:9: log line
pass_test.go:10: log
multi
line]]></system-out>
</testcase>
</testsuite>
</testsuites>

View File

@ -7,7 +7,9 @@
<testcase name="TestSubtests" classname="package/subtests" time="0.000">
<failure message="Failed"></failure>
</testcase>
<testcase name="TestSubtests/Subtest" classname="package/subtests" time="0.000"></testcase>
<testcase name="TestSubtests/Subtest" classname="package/subtests" time="0.000">
<system-out><![CDATA[ subtests_test.go:7: ok]]></system-out>
</testcase>
<testcase name="TestSubtests/Subtest#01" classname="package/subtests" time="0.000">
<failure message="Failed"><![CDATA[ subtests_test.go:10: error message]]></failure>
</testcase>
@ -24,7 +26,9 @@
<testcase name="TestFailingSubtestWithNestedSubtest/Subtest" classname="package/subtests" time="0.000">
<failure message="Failed"><![CDATA[ subtests_test.go:31: Subtest error message]]></failure>
</testcase>
<testcase name="TestFailingSubtestWithNestedSubtest/Subtest/Subsubtest" classname="package/subtests" time="0.000"></testcase>
<testcase name="TestFailingSubtestWithNestedSubtest/Subtest/Subsubtest" classname="package/subtests" time="0.000">
<system-out><![CDATA[ subtests_test.go:29: ok]]></system-out>
</testcase>
<system-out><![CDATA[exit status 1]]></system-out>
</testsuite>
</testsuites>

View File

@ -4,7 +4,9 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="TestZ" classname="package/name" time="0.060"></testcase>
<testcase name="TestZ" classname="package/name" time="0.060">
<system-out><![CDATA[some inline text]]></system-out>
</testcase>
<testcase name="TestA" classname="package/name" time="0.100"></testcase>
</testsuite>
</testsuites>

View File

@ -29,9 +29,28 @@ single-line stdout]]></failure>
<testcase name="TestFailWithNoTestOutput" classname="package/stdout" time="0.000">
<failure message="Failed"></failure>
</testcase>
<testcase name="TestPassWithStdoutAndTestOutput" classname="package/stdout" time="0.000"></testcase>
<testcase name="TestPassWithStdoutAndNoTestOutput" classname="package/stdout" time="0.000"></testcase>
<testcase name="TestPassWithTestOutput" classname="package/stdout" time="0.000"></testcase>
<testcase name="TestPassWithStdoutAndTestOutput" classname="package/stdout" time="0.000">
<system-out><![CDATA[multi
line
stdout
single-line stdout
stdout_test.go:33: single-line info
stdout_test.go:34: multi
line
info]]></system-out>
</testcase>
<testcase name="TestPassWithStdoutAndNoTestOutput" classname="package/stdout" time="0.000">
<system-out><![CDATA[multi
line
stdout
single-line stdout]]></system-out>
</testcase>
<testcase name="TestPassWithTestOutput" classname="package/stdout" time="0.000">
<system-out><![CDATA[ stdout_test.go:43: single-line info
stdout_test.go:44: multi
line
info]]></system-out>
</testcase>
<testcase name="TestPassWithNoTestOutput" classname="package/stdout" time="0.000"></testcase>
<testcase name="TestSubtests" classname="package/stdout" time="0.000">
<failure message="Failed"></failure>
@ -61,9 +80,28 @@ single-line stdout]]></failure>
<testcase name="TestSubtests/TestFailWithNoTestOutput" classname="package/stdout" time="0.000">
<failure message="Failed"></failure>
</testcase>
<testcase name="TestSubtests/TestPassWithStdoutAndTestOutput" classname="package/stdout" time="0.000"></testcase>
<testcase name="TestSubtests/TestPassWithStdoutAndNoTestOutput" classname="package/stdout" time="0.000"></testcase>
<testcase name="TestSubtests/TestPassWithTestOutput" classname="package/stdout" time="0.000"></testcase>
<testcase name="TestSubtests/TestPassWithStdoutAndTestOutput" classname="package/stdout" time="0.000">
<system-out><![CDATA[multi
line
stdout
single-line stdout
stdout_test.go:33: single-line info
stdout_test.go:34: multi
line
info]]></system-out>
</testcase>
<testcase name="TestSubtests/TestPassWithStdoutAndNoTestOutput" classname="package/stdout" time="0.000">
<system-out><![CDATA[multi
line
stdout
single-line stdout]]></system-out>
</testcase>
<testcase name="TestSubtests/TestPassWithTestOutput" classname="package/stdout" time="0.000">
<system-out><![CDATA[ stdout_test.go:43: single-line info
stdout_test.go:44: multi
line
info]]></system-out>
</testcase>
<testcase name="TestSubtests/TestPassWithNoTestOutput" classname="package/stdout" time="0.000"></testcase>
<system-out><![CDATA[exit status 1]]></system-out>
</testsuite>

View File

@ -4,14 +4,90 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="TestFlat" classname="package/whitespace" time="0.000"></testcase>
<testcase name="TestWithSpace" classname="package/whitespace" time="0.000"></testcase>
<testcase name="TestWithTab" classname="package/whitespace" time="0.000"></testcase>
<testcase name="TestWithNewlinesFlat" classname="package/whitespace" time="0.000"></testcase>
<testcase name="TestFlat" classname="package/whitespace" time="0.000">
<system-out><![CDATA[ whitespace_test.go:9: log 1
whitespace_test.go:10: log 2
printf 1
printf 2]]></system-out>
</testcase>
<testcase name="TestWithSpace" classname="package/whitespace" time="0.000">
<system-out><![CDATA[ whitespace_test.go:16: no-space
whitespace_test.go:17: one-space
whitespace_test.go:18: two-space
whitespace_test.go:19: four-space
whitespace_test.go:20: eight-space
whitespace_test.go:21: no-space
no-space
one-space
two-space
four-space
eight-space
no-space]]></system-out>
</testcase>
<testcase name="TestWithTab" classname="package/whitespace" time="0.000">
<system-out><![CDATA[ whitespace_test.go:31: no-tab
whitespace_test.go:32: one-tab
whitespace_test.go:33: two-tab
no-tab
one-tab
two-tab]]></system-out>
</testcase>
<testcase name="TestWithNewlinesFlat" classname="package/whitespace" time="0.000">
<system-out><![CDATA[ whitespace_test.go:40: no-newline
whitespace_test.go:41: one-newline
one-newline
whitespace_test.go:42: two-newlines
two-newlines
two-newlines
no-newline
one-newline
one-newline
two-newlines
two-newlines
two-newlines]]></system-out>
</testcase>
<testcase name="TestSubTests" classname="package/whitespace" time="0.000"></testcase>
<testcase name="TestSubTests/TestFlat" classname="package/whitespace" time="0.000"></testcase>
<testcase name="TestSubTests/TestWithSpace" classname="package/whitespace" time="0.000"></testcase>
<testcase name="TestSubTests/TestWithTab" classname="package/whitespace" time="0.000"></testcase>
<testcase name="TestSubTests/TestWithNewlinesFlat" classname="package/whitespace" time="0.000"></testcase>
<testcase name="TestSubTests/TestFlat" classname="package/whitespace" time="0.000">
<system-out><![CDATA[ whitespace_test.go:9: log 1
whitespace_test.go:10: log 2
printf 1
printf 2]]></system-out>
</testcase>
<testcase name="TestSubTests/TestWithSpace" classname="package/whitespace" time="0.000">
<system-out><![CDATA[ whitespace_test.go:16: no-space
whitespace_test.go:17: one-space
whitespace_test.go:18: two-space
whitespace_test.go:19: four-space
whitespace_test.go:20: eight-space
whitespace_test.go:21: no-space
no-space
one-space
two-space
four-space
eight-space
no-space]]></system-out>
</testcase>
<testcase name="TestSubTests/TestWithTab" classname="package/whitespace" time="0.000">
<system-out><![CDATA[ whitespace_test.go:31: no-tab
whitespace_test.go:32: one-tab
whitespace_test.go:33: two-tab
no-tab
one-tab
two-tab]]></system-out>
</testcase>
<testcase name="TestSubTests/TestWithNewlinesFlat" classname="package/whitespace" time="0.000">
<system-out><![CDATA[ whitespace_test.go:40: no-newline
whitespace_test.go:41: one-newline
one-newline
whitespace_test.go:42: two-newlines
two-newlines
two-newlines
no-newline
one-newline
one-newline
two-newlines
two-newlines
two-newlines]]></system-out>
</testcase>
</testsuite>
</testsuites>

11
testdata/037-legacy-fail.txt vendored Normal file
View File

@ -0,0 +1,11 @@
=== RUN TestOne
--- FAIL: TestOne (0.02 seconds)
file_test.go:11: Error message
file_test.go:11: Longer
error
message.
=== RUN TestTwo
--- PASS: TestTwo (0.13 seconds)
FAIL
exit status 1
FAIL package/name 0.151s

17
testdata/037-report.xml vendored Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="2" failures="1">
<testsuite name="package/name" tests="2" failures="1" errors="0" hostname="hostname" time="0.151" timestamp="2022-01-01T00:00:00Z">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="TestOne" classname="package/name" time="0.020">
<failure message="Failed"></failure>
</testcase>
<testcase name="TestTwo" classname="package/name" time="0.130"></testcase>
<system-out><![CDATA[ file_test.go:11: Error message
file_test.go:11: Longer
error
message.
exit status 1]]></system-out>
</testsuite>
</testsuites>

View File

@ -4,13 +4,17 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="TestAck" classname="package/name/main/ack" time="0.000"></testcase>
<testcase name="TestAck" classname="package/name/main/ack" time="0.000">
<system-out><![CDATA[ ack_test.go:13: ack]]></system-out>
</testcase>
</testsuite>
<testsuite name="package/name/main/ok" tests="1" failures="0" errors="0" hostname="hostname" time="0.000" timestamp="2022-01-01T00:00:00Z">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="TestOk" classname="package/name/main/ok" time="0.000"></testcase>
<testcase name="TestOk" classname="package/name/main/ok" time="0.000">
<system-out><![CDATA[ ok_test.go:13: ok]]></system-out>
</testcase>
</testsuite>
<testsuite name="package/name/main/fail" tests="1" failures="0" errors="1" hostname="hostname" time="0.001" timestamp="2022-01-01T00:00:00Z">
<properties>

View File

@ -4,7 +4,9 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="TestOne" classname="package/name/paniclate" time="0.000"></testcase>
<testcase name="TestOne" classname="package/name/paniclate" time="0.000">
<system-out><![CDATA[ main_test.go:13: ok]]></system-out>
</testcase>
<testcase name="Failure" classname="package/name/paniclate" time="0.000">
<error message="Runtime error"><![CDATA[panic: panic

View File

@ -4,8 +4,12 @@
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase name="TestA" classname="package/name/bench" time="0.000"></testcase>
<testcase name="TestZ" classname="package/name/bench" time="0.000"></testcase>
<testcase name="TestA" classname="package/name/bench" time="0.000">
<system-out><![CDATA[ a_test.go:6: ok]]></system-out>
</testcase>
<testcase name="TestZ" classname="package/name/bench" time="0.000">
<system-out><![CDATA[ z_test.go:6: ok]]></system-out>
</testcase>
<testcase name="BenchmarkTest" classname="package/name/bench" time="0.000000000"></testcase>
<testcase name="BenchmarkOtherTest" classname="package/name/bench" time="0.000000000"></testcase>
<system-out><![CDATA[goos: linux