Documentation
¶
Overview ¶
Package xunit defines types and utility functions in order to generate XML reports. The reports comply with the JUnit XML schema defined at: https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dashify ¶
Dashify returns the input string where all whitespace and underscore characters have been replaced by dashes and, aside from dashes, only alphanumeric characters remain. This is designed to be used to strip the "id" XML attribute of special characters.
func OutputPath ¶ added in v0.9.0
OutputPath returns a function to select different paths to save XML reports. When writing multiple reports to files, the resulting function can be used to add a prefix to each file name, and then save it to a directory with the same name as the prefix. This allows tools like test fusion and TestGrid to distinguish tests with the same name in the different reports and display their results correctly.
Types ¶
type Error ¶
type Error struct {
XMLName xml.Name `xml:"error"`
Message string `xml:"message,attr,omitempty"`
Text string `xml:",chardata"`
}
Error encapsulates metadata regarding a test error.
type Property ¶ added in v0.10.0
type Property struct {
XMLName xml.Name `xml:"property"`
Key string `xml:"name,attr"`
Value string `xml:"value,attr"`
}
Property encapsulates metadata regarding a test property.
type Report ¶
type Report struct {
XMLName xml.Name `xml:"testsuites"`
Name string `xml:"name,attr"`
TestCount int `xml:"tests,attr"`
ErrorCount int `xml:"errors,attr"`
TimeInSeconds float64 `xml:"time,attr"`
Suites []*TestSuite `xml:"testsuite"`
}
Report encapsulates the data for a xUnit XML report.
func (*Report) Finalize ¶
func (r *Report) Finalize()
Finalize iterates over the document object model and recomputes the counter values for parent objects. This ensures, for instance, that the errors attribute of a test suite specifies the correct sum of errors from its child test cases. This method should be called once all test cases are complete.
func (*Report) Split ¶ added in v0.9.0
Split separates each test suite into a separate XML report. The reports are returned as a map of test suite names to XML reports, where each report contains a single test suite.
func (*Report) WriteToStream ¶
func (r *Report) WriteToStream(w io.Writer, opts ReportWritingOptions) error
WriteToStream accepts any io.Writer and writes the contents of the report to the stream. It accepts a ReportWritingOptions instance, which provides additional granularity for tweaking the output. The method r.Finalize() should be called before writing the report.
type ReportWritingOptions ¶
type ReportWritingOptions struct {
// Number of spaces which should be used for indentation.
IndentSize int
// Number of times to retry if writing to a stream fails and no progress is
// being made on each retry.
MaxRetries int
}
ReportWritingOptions wraps optional settings for the output report.
type TestCase ¶
type TestCase struct {
XMLName xml.Name `xml:"testcase"`
Name string `xml:"name,attr"`
TimeInSeconds float64 `xml:"time,attr"`
Errors []*Error `xml:"error"`
Properties []*Property `xml:"properties>property"`
}
TestCase encapsulates metadata regarding a single test.
type TestSuite ¶
type TestSuite struct {
XMLName xml.Name `xml:"testsuite"`
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
TestCount int `xml:"tests,attr"`
ErrorCount int `xml:"errors,attr"`
TimeInSeconds float64 `xml:"time,attr"`
Cases []*TestCase `xml:"testcase"`
}
TestSuite encapsulates metadata for a collection of test cases.