reporter

package
v0.13.3-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package reporter provides test result reporters. It is intended to be used in scenarigo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(f func(r Reporter), opts ...Option) bool

Run runs f with new Reporter which applied opts. It reports whether f succeeded.

Types

type Option

type Option func(*testContext)

Option represents an option for test reporter.

func WithMaxParallel

func WithMaxParallel(i int) Option

WithMaxParallel returns an option to set the number of parallel.

func WithNoColor

func WithNoColor() Option

WithNoColor returns an option to disable colored log.

func WithVerboseLog

func WithVerboseLog() Option

WithVerboseLog returns an option to enable verbose log.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter returns an option to set the writer.

type ReportLogs

type ReportLogs struct {
	Info  []string `json:"info,omitempty"`
	Error []string `json:"error,omitempty"`
	Skip  *string  `json:"skip,omitempty"`
}

type Reporter

type Reporter interface {
	Name() string
	Fail()
	Failed() bool
	FailNow()
	Log(args ...interface{})
	Logf(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Skip(args ...interface{})
	Skipf(format string, args ...interface{})
	SkipNow()
	Skipped() bool
	Parallel()
	Run(name string, f func(r Reporter)) bool
	// contains filtered or unexported methods
}

A Reporter is something that can be used to report test results.

func FromT

func FromT(t *testing.T) Reporter

FromT creates Reporter from t.

type ScenarioFileReport

type ScenarioFileReport struct {
	Name      string           `json:"name" xml:"name,attr,omitempty"`
	Result    TestResult       `json:"result" xml:"-"`
	Duration  TestDuration     `json:"duration" xml:"time,attr"`
	Scenarios []ScenarioReport `json:"scenarios" xml:"testcase"`
}

ScenarioFileReport represents a result report of a test scenario file.

func (ScenarioFileReport) MarshalXML

func (r ScenarioFileReport) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements xml.Marshaler interface.

type ScenarioReport

type ScenarioReport struct {
	Name     string       `json:"name"`
	File     string       `json:"-"`
	Result   TestResult   `json:"result"`
	Duration TestDuration `json:"duration"`
	Steps    []StepReport `json:"steps"`
}

ScenarioReport represents a result report of a test scenario.

func (ScenarioReport) MarshalXML

func (r ScenarioReport) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements xml.Marshaler interface.

type StepReport

type StepReport struct {
	Name     string          `json:"name"`
	Result   TestResult      `json:"result"`
	Duration TestDuration    `json:"duration"`
	Logs     ReportLogs      `json:"logs"`
	SubSteps []SubStepReport `json:"subSteps,omitempty"`
}

StepReport represents a result report of a test scenario step.

type SubStepReport

type SubStepReport struct {
	Name     string          `json:"name"`
	Result   TestResult      `json:"result"`
	Duration TestDuration    `json:"duration"`
	Logs     ReportLogs      `json:"logs"`
	SubSteps []SubStepReport `json:"subSteps,omitempty"`
}

SubStepReport represents a result report of a test scenario sub step.

type TestDuration

type TestDuration time.Duration

TestDuration represents an elapsed time of a test.

func (TestDuration) MarshalJSON

func (d TestDuration) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (TestDuration) MarshalXMLAttr

func (d TestDuration) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalYAML implements xml.Marshaler interface.

func (TestDuration) MarshalYAML

func (d TestDuration) MarshalYAML() ([]byte, error)

MarshalYAML implements yaml.Marshaler interface.

func (*TestDuration) UnmarshalJSON

func (d *TestDuration) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler interface.

func (*TestDuration) UnmarshalYAML

func (d *TestDuration) UnmarshalYAML(b []byte) error

UnmarshalYAML implements yaml.Unmarshaler interface.

type TestReport

type TestReport struct {
	XMLName xml.Name             `json:"-" xml:"testsuites"`
	Name    string               `json:"name,omitempty" xml:"name,attr,omitempty"`
	Result  TestResult           `json:"result" xml:"-"`
	Files   []ScenarioFileReport `json:"files" xml:"testsuite"`
}

TestReport represents a test result report. This struct can be marshalled as JUnit-like format XML.

b, err := xml.MarshalIndent(test.report, "", "  ")
if err != nil {
	panic(err)
}
fmt.Println(b)

func GenerateTestReport

func GenerateTestReport(r Reporter) (*TestReport, error)

GenerateTestReport generates a test result report from r.

type TestResult

type TestResult int

TestResult represents a test result.

const (
	TestResultUndefined TestResult = iota
	TestResultPassed
	TestResultFailed
	TestResultSkipped
)

func (TestResult) MarshalJSON

func (r TestResult) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (TestResult) MarshalYAML

func (r TestResult) MarshalYAML() ([]byte, error)

MarshalYAML implements yaml.Marshaler interface.

func (TestResult) String

func (r TestResult) String() string

String returns r as a string.

func (*TestResult) UnmarshalJSON

func (r *TestResult) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler interface.

func (*TestResult) UnmarshalYAML

func (r *TestResult) UnmarshalYAML(b []byte) error

UnmarshalYAML implements yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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