surefire

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Surefire Result Parser

Reads Surefire Results from multiple XML files and aggregates then for further processing.

Features

Surefire XML Test results are parsed into structs. Data Model shows the data-structure surefire results is converted to.

Installation

  • Install Go, at least version 1.21.0
  • Run make local-build. This will resolve dependencies and run tests

Usage

Add module by go get github.com/adobe/go-surefire.

Read test-result XML files from ~/test-results directory.

files, _ := listTestReportFiles()

testResults, err := NewJUnitReportsReaderBuilder().Build().FromReportFiles(files)
	
func listTestReportFiles() ([]string, error) {
	sureFireTestResult := []string{}
	items, err := os.ReadDir(~/test-results)

	if err != nil {
		return nil, err
	}

	for _, item := range items {
		if item.Type().IsRegular() && strings.HasSuffix(item.Name(), ".xml") {
			sureFireTestResult = append(sureFireTestResult, fmt.Sprintf("%s/%s", path, item.Name()))
		}
	}

	return sureFireTestResult, nil
}

There is also support for adding labels to results on Suite level.

files, _ := listTestReportFiles()

testResults, err := NewJUnitReportsReaderBuilder().WithLabeler(func(suite TestSuite) []string {
		return []string{"label"}
	}).Build().FromReportFiles(files)
Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Issue

type Issue struct {
	// Message for that issue
	Message string
	// Details for that issue
	Detail string
}

Issue encapsulates a failure or error

type JUnitReportsReader

type JUnitReportsReader struct {
	// contains filtered or unexported fields
}

func (*JUnitReportsReader) FromJUnitRepresentation

func (b *JUnitReportsReader) FromJUnitRepresentation(surefireSuites []surefireTestsuite) TestResults

func (*JUnitReportsReader) FromReportFiles

func (b *JUnitReportsReader) FromReportFiles(surefireReportFiles []string) (TestResults, error)

type JUnitReportsReaderBuilder

type JUnitReportsReaderBuilder struct {
	JUnitReportsReader JUnitReportsReader
}

func NewJUnitReportsReaderBuilder

func NewJUnitReportsReaderBuilder() *JUnitReportsReaderBuilder

func (*JUnitReportsReaderBuilder) Build

func (*JUnitReportsReaderBuilder) WithLabeler

type Labeler

type Labeler func(TestSuite) []string

type RerunIssue

type RerunIssue struct {
	// Message for that RerunIssue
	Message string
	// Stacktrace for that RerunIssue
	Stacktrace string
	// SystemOut for that RerunIssue
	SystemOut string
	// SystemError for that RerunIssue
	SystemError string
}

RerunIssue encapsulates a rerun failure or error

type Skipped

type Skipped struct {
	Message string
}

Issue encapsulates the message of a skipped test

type Status

type Status string

Status represents the status of a test case

const (
	Success Status = "success"
	Skip    Status = "skipped"
	Failure Status = "failure"
	Error   Status = "error"
	Flaky   Status = "flaky"
)

type TestCase

type TestCase struct {
	// Name of the test case
	Name string

	// Backreference to the suite this test case belongs to
	Suite TestSuite

	// Status of this test case
	Status Status

	// The time this test case needs to run
	Time float64

	// Full qualified name of the test case
	Fullname string

	// Classname of this test case
	Classname string

	// Issue this test case has. If nil there was no issue with it
	Issue *Issue

	// The failures which appeared that leads to a re-run of this failing test
	RerunFailures []RerunIssue

	// The amount of failure which appeared that leads to a re-run of this test
	AmountRerunFailures int

	// The errors which appeared that leads to a re-run of this test in error
	RerunErrors []RerunIssue

	// The amount of errors which appeared that leads to a re-run of this test
	AmountRerunErrors int

	// The failures which appeared that leads to a re-run of this flaky test
	FlakyFailures []RerunIssue

	// The amount of failures which appeared that leads to a re-run of this flaky test
	AmountFlakyFailures int

	// The errors which appeared that leads to a re-run of this flaky test
	FlakyErrors []RerunIssue

	// The amount of errors which appeared that leads to a re-run of this flaky test
	AmountFlakyErrors int

	// Set for a skipped test, nil otherwise
	Skipped *Skipped
}

TestCase represents a single test run

type TestResults

type TestResults interface {
	// All being read from the surefire reports. Except for those with an empty name attribute
	TestSuites() []TestSuite

	// The amount of a all tests
	Tests() int

	// The amount of tests that were successful
	Successes() int

	// The amount of failing tests
	Failures() int

	// The amount of tests in error
	Errors() int

	// The amount of skipped tests
	Skipped() int

	// The amount flaky tests
	Flakes() int
}

TestResults aggregates all TestSuites being read from the surefire reports and expose statistics

type TestSuite

type TestSuite interface {
	// Returns all test cases
	TestCases() []TestCase

	// Returns non successful test cases, either failing or in error
	NonSuccessfulTestCases() []TestCase

	// Returns successful test cases
	SuccessfulTestCases() []TestCase

	// Returns skipped test cases
	SkippedTestCases() []TestCase

	// Returns flaky test cases
	FlakyTestCases() []TestCase

	// The amount of successful tests in this suite
	Success() int

	// The amount of failing tests in this suite
	Failure() int

	// The amount of tests in this suite that are in error
	Error() int

	// The amount of skipped tests in this suite
	Skipped() int

	// Name of the suite
	Name() string

	// Filename from which the result was coming from
	Filename() string

	// The time this suite needs to run
	Time() float64

	// Labels the suite is assigned to
	Labels() []string
}

TestSuite represents a set of TestCase and exposes statistics

Jump to

Keyboard shortcuts

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