Documentation
¶
Overview ¶
Package junit 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 ¶
Types ¶
type Failure ¶
type Failure struct {
XMLName xml.Name `xml:"failure"`
Type FailureType `xml:"type,attr"`
Message string `xml:"message,attr"`
Text string `xml:",chardata"`
}
Failure encapsulates metadata regarding a test failure or warning.
type FailureType ¶
type FailureType string
FailureType is a possible value of the "type" attribute on the Failure JUnit XML tag.
const ( // Warning signals that an error occurred which is not fatal. Warning FailureType = "warning" // Error signals that an error occurred which is fatal. Error FailureType = "error" )
type Report ¶
type Report struct {
XMLName xml.Name `xml:"testsuites"`
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
TestCount int `xml:"tests,attr"`
FailureCount int `xml:"failures,attr"`
TimeInSeconds float64 `xml:"time,attr"`
Suites []*TestSuite `xml:"testsuite"`
}
Report encapsulates the data for a JUnit XML report.
func (*Report) Finalize ¶
Finalize makes a deep copy of the report. Then, it recursively maps over the document object model and recomputes the counter values for parent objects. This ensures, for instance, that the failures attribute of a test suite specifies the correct sum of failures from its child test cases. Finally, it returns the copy with the correct values.
This immutability ensures that there is thread-safety between reading and writing to the report. This allows the report to be written even if not all test cases have completed without harming later reporting.
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.
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"`
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
TimeInSeconds float64 `xml:"time,attr"`
Failures []*Failure `xml:"failure"`
}
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"`
FailureCount int `xml:"failures,attr"`
TimeInSeconds float64 `xml:"time,attr"`
Cases []*TestCase `xml:"testcase"`
}
TestSuite encapsulates metadata for a collection of test cases.