mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-07-06 14:02:52 -05:00
Add properties to xml report
Include the go runtime version as a property.
This commit is contained in:
@ -5,16 +5,18 @@ import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type JUnitTestSuite struct {
|
||||
XMLName xml.Name `xml:"testsuite"`
|
||||
Tests int `xml:"tests,attr"`
|
||||
Failures int `xml:"failures,attr"`
|
||||
Time string `xml:"time,attr"`
|
||||
Name string `xml:"name,attr"`
|
||||
TestCases []JUnitTestCase
|
||||
XMLName xml.Name `xml:"testsuite"`
|
||||
Tests int `xml:"tests,attr"`
|
||||
Failures int `xml:"failures,attr"`
|
||||
Time string `xml:"time,attr"`
|
||||
Name string `xml:"name,attr"`
|
||||
Properties []JUnitProperty `xml:"properties>property,omitempty"`
|
||||
TestCases []JUnitTestCase
|
||||
}
|
||||
|
||||
type JUnitTestCase struct {
|
||||
@ -25,17 +27,30 @@ type JUnitTestCase struct {
|
||||
Failure string `xml:"failure,omitempty"`
|
||||
}
|
||||
|
||||
type JUnitProperty struct {
|
||||
Name string `xml:"name,attr"`
|
||||
Value string `xml:"value,attr"`
|
||||
}
|
||||
|
||||
func NewJUnitProperty(name, value string) JUnitProperty {
|
||||
return JUnitProperty{
|
||||
Name: name,
|
||||
Value: value,
|
||||
}
|
||||
}
|
||||
|
||||
func JUnitReportXML(report *Report, w io.Writer) error {
|
||||
suites := []JUnitTestSuite{}
|
||||
|
||||
// convert Report to JUnit test suites
|
||||
for _, pkg := range report.Packages {
|
||||
ts := JUnitTestSuite{
|
||||
Tests: len(pkg.Tests),
|
||||
Failures: 0,
|
||||
Time: formatTime(pkg.Time),
|
||||
Name: pkg.Name,
|
||||
TestCases: []JUnitTestCase{},
|
||||
Tests: len(pkg.Tests),
|
||||
Failures: 0,
|
||||
Time: formatTime(pkg.Time),
|
||||
Name: pkg.Name,
|
||||
Properties: []JUnitProperty{},
|
||||
TestCases: []JUnitTestCase{},
|
||||
}
|
||||
|
||||
classname := pkg.Name
|
||||
@ -43,6 +58,9 @@ func JUnitReportXML(report *Report, w io.Writer) error {
|
||||
classname = pkg.Name[idx+1:]
|
||||
}
|
||||
|
||||
// properties
|
||||
ts.Properties = append(ts.Properties, NewJUnitProperty("go.version", runtime.Version()))
|
||||
|
||||
// individual test cases
|
||||
for _, test := range pkg.Tests {
|
||||
testCase := JUnitTestCase{
|
||||
|
Reference in New Issue
Block a user