reporter

package
v0.13.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 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 added in v0.7.0

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 added in v0.6.2

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 added in v0.6.2

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 added in v0.6.2

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

MarshalXML implements xml.Marshaler interface.

type ScenarioReport added in v0.6.2

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 added in v0.6.2

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

MarshalXML implements xml.Marshaler interface.

type StepReport added in v0.6.2

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 added in v0.6.2

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 added in v0.6.2

type TestDuration time.Duration

TestDuration represents an elapsed time of a test.

func (TestDuration) MarshalJSON added in v0.6.2

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

MarshalJSON implements json.Marshaler interface.

func (TestDuration) MarshalXMLAttr added in v0.6.2

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

MarshalYAML implements xml.Marshaler interface.

func (TestDuration) MarshalYAML added in v0.6.2

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

MarshalYAML implements yaml.Marshaler interface.

func (*TestDuration) UnmarshalJSON added in v0.6.2

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

UnmarshalJSON implements json.Unmarshaler interface.

func (*TestDuration) UnmarshalYAML added in v0.6.2

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

UnmarshalYAML implements yaml.Unmarshaler interface.

type TestReport added in v0.6.2

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 added in v0.6.2

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

GenerateTestReport generates a test result report from r.

type TestResult added in v0.6.2

type TestResult int

TestResult represents a test result.

const (
	TestResultUndefined TestResult = iota
	TestResultPassed
	TestResultFailed
	TestResultSkipped
)

func (TestResult) MarshalJSON added in v0.6.2

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

MarshalJSON implements json.Marshaler interface.

func (TestResult) MarshalYAML added in v0.6.2

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

MarshalYAML implements yaml.Marshaler interface.

func (TestResult) String added in v0.6.2

func (r TestResult) String() string

String returns r as a string.

func (*TestResult) UnmarshalJSON added in v0.6.2

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

UnmarshalJSON implements json.Unmarshaler interface.

func (*TestResult) UnmarshalYAML added in v0.6.2

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