junit

package
v0.184.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const FileName = "junit.xml"

FileName is the name of the JUnit report.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error added in v0.156.0

type Error struct {
	// Message is a short description of the error.
	Message string `xml:"message,attr"`
	// Type is the type of error, e.g. "java.lang.NullPointerException".
	Type string `xml:"type,attr"`
	// Text is an error description or stack trace.
	Text string `xml:",chardata"`
}

Error maps to <error> element. It usually indicates unexpected errors. Some frameworks use Failure or the 'status' attribute on TestCase instead.

type Failure added in v0.156.0

type Failure struct {
	// Message is a short description of the failure.
	Message string `xml:"message,attr"`
	// Type is the type of failure, e.g. "java.lang.AssertionError".
	Type string `xml:"type,attr"`
	// Text is a failure description or stack trace.
	Text string `xml:",chardata"`
}

Failure maps to either a <failure> or <error> element. It usually indicates assertion failures. Depending on the framework, this may also indicate an unexpected error, much like Error does. Some frameworks use Error or the 'status' attribute on TestCase instead.

type Property added in v0.62.0

type Property struct {
	Name  string `xml:"name,attr"`
	Value string `xml:"value,attr"`
}

Property maps to a <property> element that's part of <properties>.

type Skipped added in v0.156.0

type Skipped struct {
	// Message is a short description that explains why the test was skipped.
	Message string `xml:"message,attr"`
}

Skipped maps to <skipped> element. Indicates a skipped test. Some frameworks use the 'status' attribute on TestCase instead.

type TestCase

type TestCase struct {
	Name string `xml:"name,attr"`
	// Assertions is the number of assertions in the test case.
	Assertions string `xml:"assertions,attr,omitempty"`
	// Time in seconds it took to run the test case.
	Time string `xml:"time,attr"`
	// Timestamp as specified by ISO 8601 (2014-01-21T16:17:18).
	// Timezone is optional.
	Timestamp string `xml:"timestamp,attr"`
	ClassName string `xml:"classname,attr"`
	// Status indicates success or failure of the test. May be used instead of
	// Error, Failure or Skipped or in addition to them.
	Status    string   `xml:"status,attr,omitempty"`
	File      string   `xml:"file,attr,omitempty"`
	SystemErr string   `xml:"system-err,omitempty"`
	SystemOut string   `xml:"system-out,omitempty"`
	Error     *Error   `xml:"error,omitempty"`
	Failure   *Failure `xml:"failure,omitempty"`
	Skipped   *Skipped `xml:"skipped,omitempty"`
}

TestCase maps to <testcase> element

func (TestCase) IsError added in v0.156.0

func (tc TestCase) IsError() bool

IsError returns true if the test case errored. Multiple fields are taken into account to determine this.

func (TestCase) IsFailure added in v0.156.0

func (tc TestCase) IsFailure() bool

IsFailure returns true if the test case failed. Multiple fields are taken into account to determine this.

func (TestCase) IsSkipped added in v0.156.0

func (tc TestCase) IsSkipped() bool

IsSkipped returns true if the test case was skipped. Multiple fields are taken into account to determine this.

type TestSuite

type TestSuite struct {
	Name       string     `xml:"name,attr"`
	Tests      int        `xml:"tests,attr"`
	Properties []Property `xml:"properties>property"`
	Errors     int        `xml:"errors,attr,omitempty"`
	Failures   int        `xml:"failures,attr,omitempty"`
	// Disabled is the number of disabled or skipped tests. Some frameworks use Skipped instead.
	Disabled int `xml:"disabled,attr,omitempty"`
	// Skipped is the number of skipped or disabled tests. Some frameworks use Disabled instead.
	Skipped int `xml:"skipped,attr,omitempty"`
	// Time in seconds it took to run the test suite.
	Time string `xml:"time,attr,omitempty"`
	// Timestamp as specified by ISO 8601 (2014-01-21T16:17:18). Timezone may not be specified.
	Timestamp string     `xml:"timestamp,attr,omitempty"`
	Package   string     `xml:"package,attr,omitempty"`
	File      string     `xml:"file,attr,omitempty"`
	TestCases []TestCase `xml:"testcase"`
	SystemErr string     `xml:"system-err,omitempty"`
	SystemOut string     `xml:"system-out,omitempty"`
}

TestSuite maps to <testsuite> element

func (*TestSuite) AddTestCases added in v0.156.0

func (ts *TestSuite) AddTestCases(unique bool, tcs ...TestCase)

AddTestCases adds test cases to the test suite. If unique is true, existing test cases with the same name will be replaced.

func (*TestSuite) Compute added in v0.156.0

func (ts *TestSuite) Compute()

Compute updates some statistics for the test suite based on the test cases it contains.

Updates the following fields:

  • Tests
  • Errors
  • Failures
  • Skipped/Disabled

type TestSuites

type TestSuites struct {
	XMLName    xml.Name    `xml:"testsuites"`
	TestSuites []TestSuite `xml:"testsuite"`
	Name       string      `xml:"name,attr,omitempty"`
	// Time in seconds it took to run all the test suites.
	Time  string `xml:"time,attr,omitempty"`
	Tests int    `xml:"tests,attr,omitempty"`
	// Disabled is the number of disabled or skipped tests. Some frameworks use Skipped instead.
	Disabled int `xml:"disabled,attr,omitempty"`
	// Skipped is the number of skipped or disabled tests. Some frameworks use Disabled instead.
	Skipped  int `xml:"skipped,attr,omitempty"`
	Failures int `xml:"failures,attr,omitempty"`
	Errors   int `xml:"errors,attr,omitempty"`
}

TestSuites maps to root junit <testsuites> element

func MergeReports added in v0.156.0

func MergeReports(reports ...TestSuites) TestSuites

MergeReports merges multiple junit reports into a single report.

func Parse

func Parse(data []byte) (TestSuites, error)

Parse a junit report from an XML encoded byte string. The root <testsuites> element is optional if there's only one <testsuite> element. In that case, Parse will parse the <testsuite> and wrap it in a TestSuites struct.

func (*TestSuites) Compute added in v0.156.0

func (ts *TestSuites) Compute()

Compute updates _some_ statistics for the entire report based on the test cases it contains. This is an expensive and destructive operation. Use judiciously.

Updates the following fields:

  • Tests
  • Errors
  • Failures
  • Skipped/Disabled

func (*TestSuites) TestCases added in v0.156.0

func (ts *TestSuites) TestCases() []TestCase

TestCases returns all test cases from all test suites.

Jump to

Keyboard shortcuts

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