xunit

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

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

func Dashify(s string) string

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.

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 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) 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"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL