Add properties to xml report

Include the go runtime version as a property.
This commit is contained in:
Joel Stemmer
2012-03-16 15:39:57 +01:00
parent 8cf088e24f
commit d72fb56d06
4 changed files with 54 additions and 16 deletions

View File

@ -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{