|
| 1 | +package junitapi |
| 2 | + |
| 3 | +import "encoding/xml" |
| 4 | + |
| 5 | +// The below types are directly marshalled into XML. The types correspond to jUnit |
| 6 | +// XML schema, but do not contain all valid fields. For instance, the class name |
| 7 | +// field for test cases is omitted, as this concept does not directly apply to Go. |
| 8 | +// For XML specifications see http://help.catchsoftware.com/display/ET/JUnit+Format |
| 9 | +// or view the XSD included in this package as 'junit.xsd' |
| 10 | + |
| 11 | +// Usage is something like |
| 12 | +// import "encoding/xml" |
| 13 | +// out, err := xml.MarshalIndent(s, "", " ") |
| 14 | +// if err != nil { |
| 15 | +// return err |
| 16 | +// } |
| 17 | + |
| 18 | +// TestSuites represents a flat collection of jUnit test suites. |
| 19 | +type JUnitTestSuites struct { |
| 20 | + XMLName xml.Name `xml:"testsuites"` |
| 21 | + |
| 22 | + // Suites are the jUnit test suites held in this collection |
| 23 | + Suites []*JUnitTestSuite `xml:"testsuite"` |
| 24 | +} |
| 25 | + |
| 26 | +// TestSuite represents a single jUnit test suite, potentially holding child suites. |
| 27 | +type JUnitTestSuite struct { |
| 28 | + XMLName xml.Name `xml:"testsuite"` |
| 29 | + |
| 30 | + // Name is the name of the test suite |
| 31 | + Name string `xml:"name,attr"` |
| 32 | + |
| 33 | + // NumTests records the number of tests in the TestSuite |
| 34 | + NumTests uint `xml:"tests,attr"` |
| 35 | + |
| 36 | + // NumSkipped records the number of skipped tests in the suite |
| 37 | + NumSkipped uint `xml:"skipped,attr"` |
| 38 | + |
| 39 | + // NumFailed records the number of failed tests in the suite |
| 40 | + NumFailed uint `xml:"failures,attr"` |
| 41 | + |
| 42 | + // Duration is the time taken in seconds to run all tests in the suite |
| 43 | + Duration float64 `xml:"time,attr"` |
| 44 | + |
| 45 | + // Properties holds other properties of the test suite as a mapping of name to value |
| 46 | + Properties []*TestSuiteProperty `xml:"properties,omitempty"` |
| 47 | + |
| 48 | + // TestCases are the test cases contained in the test suite |
| 49 | + TestCases []*JUnitTestCase `xml:"testcase"` |
| 50 | + |
| 51 | + // Children holds nested test suites |
| 52 | + Children []*JUnitTestSuite `xml:"testsuite"` |
| 53 | +} |
| 54 | + |
| 55 | +// TestSuiteProperty contains a mapping of a property name to a value |
| 56 | +type TestSuiteProperty struct { |
| 57 | + XMLName xml.Name `xml:"property"` |
| 58 | + |
| 59 | + Name string `xml:"name,attr"` |
| 60 | + Value string `xml:"value,attr"` |
| 61 | +} |
| 62 | + |
| 63 | +// JUnitTestCase represents a jUnit test case |
| 64 | +type JUnitTestCase struct { |
| 65 | + XMLName xml.Name `xml:"testcase"` |
| 66 | + |
| 67 | + // Name is the name of the test case |
| 68 | + Name string `xml:"name,attr"` |
| 69 | + |
| 70 | + // Classname is an attribute set by the package type and is required |
| 71 | + Classname string `xml:"classname,attr,omitempty"` |
| 72 | + |
| 73 | + // Duration is the time taken in seconds to run the test |
| 74 | + Duration float64 `xml:"time,attr"` |
| 75 | + |
| 76 | + // SkipMessage holds the reason why the test was skipped |
| 77 | + SkipMessage *SkipMessage `xml:"skipped"` |
| 78 | + |
| 79 | + // FailureOutput holds the output from a failing test |
| 80 | + FailureOutput *FailureOutput `xml:"failure"` |
| 81 | + |
| 82 | + // SystemOut is output written to stdout during the execution of this test case |
| 83 | + SystemOut string `xml:"system-out,omitempty"` |
| 84 | + |
| 85 | + // SystemErr is output written to stderr during the execution of this test case |
| 86 | + SystemErr string `xml:"system-err,omitempty"` |
| 87 | +} |
| 88 | + |
| 89 | +// SkipMessage holds a message explaining why a test was skipped |
| 90 | +type SkipMessage struct { |
| 91 | + XMLName xml.Name `xml:"skipped"` |
| 92 | + |
| 93 | + // Message explains why the test was skipped |
| 94 | + Message string `xml:"message,attr,omitempty"` |
| 95 | +} |
| 96 | + |
| 97 | +// FailureOutput holds the output from a failing test |
| 98 | +type FailureOutput struct { |
| 99 | + XMLName xml.Name `xml:"failure"` |
| 100 | + |
| 101 | + // Message holds the failure message from the test |
| 102 | + Message string `xml:"message,attr"` |
| 103 | + |
| 104 | + // Output holds verbose failure output from the test |
| 105 | + Output string `xml:",chardata"` |
| 106 | +} |
0 commit comments