junit

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

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

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 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.

func (*Failure) DeepCopy

func (f *Failure) DeepCopy() *Failure

DeepCopy makes an exact copy of a Failure object and all child objects.

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) DeepCopy

func (r *Report) DeepCopy() *Report

DeepCopy makes an exact copy of a Report object and all child objects.

func (*Report) Finalize

func (r *Report) Finalize() *Report

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.

func (*TestCase) DeepCopy

func (tc *TestCase) DeepCopy() *TestCase

DeepCopy makes an exact copy of a TestCase object and all child objects.

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.

func (*TestSuite) DeepCopy

func (ts *TestSuite) DeepCopy() *TestSuite

DeepCopy makes an exact copy of a TestSuite object and all child objects.

Jump to

Keyboard shortcuts

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