mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-06 21:48:08 -05:00
Merge pull request #93 from johnSchnake/unmarshalSuites
Adjust xml annotations to allow unmarshal of test suites
This commit is contained in:
commit
080dff894f
@ -14,8 +14,8 @@ import (
|
|||||||
|
|
||||||
// JUnitTestSuites is a collection of JUnit test suites.
|
// JUnitTestSuites is a collection of JUnit test suites.
|
||||||
type JUnitTestSuites struct {
|
type JUnitTestSuites struct {
|
||||||
XMLName xml.Name `xml:"testsuites"`
|
XMLName xml.Name `xml:"testsuites"`
|
||||||
Suites []JUnitTestSuite
|
Suites []JUnitTestSuite `xml:"testsuite"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JUnitTestSuite is a single JUnit test suite which may contain many
|
// JUnitTestSuite is a single JUnit test suite which may contain many
|
||||||
@ -27,7 +27,7 @@ type JUnitTestSuite struct {
|
|||||||
Time string `xml:"time,attr"`
|
Time string `xml:"time,attr"`
|
||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
Properties []JUnitProperty `xml:"properties>property,omitempty"`
|
Properties []JUnitProperty `xml:"properties>property,omitempty"`
|
||||||
TestCases []JUnitTestCase
|
TestCases []JUnitTestCase `xml:"testcase"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JUnitTestCase is a single test case with its result.
|
// JUnitTestCase is a single test case with its result.
|
||||||
|
64
formatter/formatter_test.go
Normal file
64
formatter/formatter_test.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package formatter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/xml"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSuites_Unmarshal(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
desc string
|
||||||
|
suites JUnitTestSuites
|
||||||
|
noXMLHeader bool
|
||||||
|
goVersion string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "Suites should marshal back and forth",
|
||||||
|
suites: JUnitTestSuites{
|
||||||
|
Suites: []JUnitTestSuite{
|
||||||
|
{
|
||||||
|
Name: "suite1",
|
||||||
|
TestCases: []JUnitTestCase{
|
||||||
|
{Name: "test1-1"},
|
||||||
|
{Name: "test1-2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "suite2",
|
||||||
|
TestCases: []JUnitTestCase{
|
||||||
|
{Name: "test2-1"},
|
||||||
|
{Name: "test2-2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Logf("Test case: %v", test.desc)
|
||||||
|
initialBytes, err := xml.Marshal(test.suites)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Expected no failure when generating xml; got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var suites JUnitTestSuites
|
||||||
|
err = xml.Unmarshal(initialBytes, &suites)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Expected no failure when unmarshaling; got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
newBytes, err := xml.Marshal(suites)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Expected no failure when generating xml again; got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bytes.Equal(newBytes, initialBytes) {
|
||||||
|
t.Errorf("Expected the same result when marshal/unmarshal/marshal. Expected\n%v\n\t but got\n%v",
|
||||||
|
string(initialBytes),
|
||||||
|
string(newBytes),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user