mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-06 21:48:08 -05:00
Add surrounding <testsuites> tag.
* If a test log contains more than one package we need to wrap it in a <testsuites> element in order to be valid xml. Bamboo cannot read the file if it is not valid xml.
This commit is contained in:
parent
18ee6df2f2
commit
6d2ab46d4f
@ -233,7 +233,7 @@ func TestJUnitFormatter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if string(junitReport.Bytes()) != report {
|
if string(junitReport.Bytes()) != report {
|
||||||
t.Fatalf("Report xml ==\n%s, want\n%s", string(junitReport.Bytes()), report)
|
t.Fatalf("Fail: %s Report xml ==\n%s, want\n%s", testCase.name, string(junitReport.Bytes()), report)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type JUnitTestSuites struct {
|
||||||
|
XMLName xml.Name `xml:"testsuites"`
|
||||||
|
Suites []JUnitTestSuite
|
||||||
|
}
|
||||||
|
|
||||||
type JUnitTestSuite struct {
|
type JUnitTestSuite struct {
|
||||||
XMLName xml.Name `xml:"testsuite"`
|
XMLName xml.Name `xml:"testsuite"`
|
||||||
Tests int `xml:"tests,attr"`
|
Tests int `xml:"tests,attr"`
|
||||||
@ -53,7 +58,7 @@ func NewJUnitProperty(name, value string) JUnitProperty {
|
|||||||
// JUnitReportXML writes a junit xml representation of the given report to w
|
// JUnitReportXML writes a junit xml representation of the given report to w
|
||||||
// in the format described at http://windyroad.org/dl/Open%20Source/JUnit.xsd
|
// in the format described at http://windyroad.org/dl/Open%20Source/JUnit.xsd
|
||||||
func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error {
|
func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error {
|
||||||
suites := []JUnitTestSuite{}
|
suites := JUnitTestSuites{}
|
||||||
|
|
||||||
// convert Report to JUnit test suites
|
// convert Report to JUnit test suites
|
||||||
for _, pkg := range report.Packages {
|
for _, pkg := range report.Packages {
|
||||||
@ -100,7 +105,7 @@ func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error {
|
|||||||
ts.TestCases = append(ts.TestCases, testCase)
|
ts.TestCases = append(ts.TestCases, testCase)
|
||||||
}
|
}
|
||||||
|
|
||||||
suites = append(suites, ts)
|
suites.Suites = append(suites.Suites, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// to xml
|
// to xml
|
||||||
@ -114,6 +119,7 @@ func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error {
|
|||||||
if !noXmlHeader {
|
if !noXmlHeader {
|
||||||
writer.WriteString(xml.Header)
|
writer.WriteString(xml.Header)
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.Write(bytes)
|
writer.Write(bytes)
|
||||||
writer.WriteByte('\n')
|
writer.WriteByte('\n')
|
||||||
writer.Flush()
|
writer.Flush()
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<testsuite tests="2" failures="0" time="0.160" name="package/name">
|
<testsuites>
|
||||||
<properties>
|
<testsuite tests="2" failures="0" time="0.160" name="package/name">
|
||||||
<property name="go.version" value="1.0"></property>
|
<properties>
|
||||||
</properties>
|
<property name="go.version" value="1.0"></property>
|
||||||
<testcase classname="name" name="TestOne" time="0.060"></testcase>
|
</properties>
|
||||||
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
|
<testcase classname="name" name="TestOne" time="0.060"></testcase>
|
||||||
</testsuite>
|
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<testsuite tests="2" failures="1" time="0.151" name="package/name">
|
<testsuites>
|
||||||
<properties>
|
<testsuite tests="2" failures="1" time="0.151" name="package/name">
|
||||||
<property name="go.version" value="1.0"></property>
|
<properties>
|
||||||
</properties>
|
<property name="go.version" value="1.0"></property>
|
||||||
<testcase classname="name" name="TestOne" time="0.020">
|
</properties>
|
||||||
<failure message="Failed" type="">file_test.go:11: Error message
file_test.go:11: Longer
	error
	message.</failure>
|
<testcase classname="name" name="TestOne" time="0.020">
|
||||||
</testcase>
|
<failure message="Failed" type="">file_test.go:11: Error message
file_test.go:11: Longer
	error
	message.</failure>
|
||||||
<testcase classname="name" name="TestTwo" time="0.130"></testcase>
|
</testcase>
|
||||||
</testsuite>
|
<testcase classname="name" name="TestTwo" time="0.130"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<testsuite tests="2" failures="0" time="0.150" name="package/name">
|
<testsuites>
|
||||||
<properties>
|
<testsuite tests="2" failures="0" time="0.150" name="package/name">
|
||||||
<property name="go.version" value="1.0"></property>
|
<properties>
|
||||||
</properties>
|
<property name="go.version" value="1.0"></property>
|
||||||
<testcase classname="name" name="TestOne" time="0.020">
|
</properties>
|
||||||
<skipped message="file_test.go:11: Skip message"></skipped>
|
<testcase classname="name" name="TestOne" time="0.020">
|
||||||
</testcase>
|
<skipped message="file_test.go:11: Skip message"></skipped>
|
||||||
<testcase classname="name" name="TestTwo" time="0.130"></testcase>
|
</testcase>
|
||||||
</testsuite>
|
<testcase classname="name" name="TestTwo" time="0.130"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<testsuite tests="2" failures="0" time="0.160" name="package/name">
|
<testsuites>
|
||||||
<properties>
|
<testsuite tests="2" failures="0" time="0.160" name="package/name">
|
||||||
<property name="go.version" value="1.0"></property>
|
<properties>
|
||||||
</properties>
|
<property name="go.version" value="1.0"></property>
|
||||||
<testcase classname="name" name="TestOne" time="0.060"></testcase>
|
</properties>
|
||||||
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
|
<testcase classname="name" name="TestOne" time="0.060"></testcase>
|
||||||
</testsuite>
|
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
<testsuite tests="2" failures="0" time="0.160" name="package/name">
|
<testsuites>
|
||||||
<properties>
|
<testsuite tests="2" failures="0" time="0.160" name="package/name">
|
||||||
<property name="go.version" value="1.0"></property>
|
<properties>
|
||||||
</properties>
|
<property name="go.version" value="1.0"></property>
|
||||||
<testcase classname="name" name="TestOne" time="0.060"></testcase>
|
</properties>
|
||||||
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
|
<testcase classname="name" name="TestOne" time="0.060"></testcase>
|
||||||
</testsuite>
|
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user