Parse test failure messages

This commit is contained in:
Joel Stemmer
2012-03-17 12:34:02 +01:00
parent bcc3b7b2d7
commit a6dab641a1
4 changed files with 64 additions and 34 deletions

View File

@ -20,11 +20,11 @@ type JUnitTestSuite struct {
}
type JUnitTestCase struct {
XMLName xml.Name `xml:"testcase"`
Classname string `xml:"classname,attr"`
Name string `xml:"name,attr"`
Time string `xml:"time,attr"`
Failure string `xml:"failure,omitempty"`
XMLName xml.Name `xml:"testcase"`
Classname string `xml:"classname,attr"`
Name string `xml:"name,attr"`
Time string `xml:"time,attr"`
Failure *JUnitFailure `xml:"failure,omitempty"`
}
type JUnitProperty struct {
@ -32,6 +32,12 @@ type JUnitProperty struct {
Value string `xml:"value,attr"`
}
type JUnitFailure struct {
Message string `xml:"message,attr"`
Type string `xml:"type,attr"`
Contents string `xml:",chardata"`
}
func NewJUnitProperty(name, value string) JUnitProperty {
return JUnitProperty{
Name: name,
@ -69,14 +75,17 @@ func JUnitReportXML(report *Report, w io.Writer) error {
Classname: classname,
Name: test.Name,
Time: formatTime(test.Time),
Failure: "",
Failure: nil,
}
if test.Result == FAIL {
ts.Failures += 1
// TODO: set error message
testCase.Failure = "Failed"
testCase.Failure = &JUnitFailure{
Message: "Failed",
Type: "",
Contents: strings.Join(test.Output, "\n"),
}
}
ts.TestCases = append(ts.TestCases, testCase)