-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjunit.go
57 lines (49 loc) · 1.36 KB
/
junit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package forest
import (
"encoding/xml"
"fmt"
"io/ioutil"
"time"
)
type JUnitReport struct {
TestSuites []JUnitTestSuite `xml:"testsuite"`
}
type JUnitTestSuite struct {
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Time float64 `xml:"time,attr"`
Name string `xml:"name,attr"`
Timestamp time.Time `xml:"timestamp,attr"`
Properties []JUnitProperty `xml:"properties"`
TestCases []JUnitTestCase `xml:"testcase"`
}
type JUnitProperty struct {
Name string `xml:"name,attr"`
Value string `xml:"value,attr"`
}
type JUnitTestCase struct {
Classname string `xml:"classname,attr"`
Name string `xml:"name,attr"`
Time float64 `xml:"time,attr"`
Failure *JUnitTestCaseFailure `xml:"failure"`
Skipped *JUnitTestCaseSkipped `xml:"skipped"`
}
type JUnitTestCaseFailure struct {
Message string `xml:"message,attr"`
Type string `xml:"type,attr"`
}
type JUnitTestCaseSkipped struct {
Message string `xml:"message,attr"`
}
func ReadJUnitReport(filename string) (r JUnitReport, err error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
err = fmt.Errorf("failed to read JUnit report:%v", err)
return
}
err = xml.Unmarshal(data, &r)
if err != nil {
err = fmt.Errorf("failed to decode JUnit report:%v", err)
}
return
}