Documentation
¶
Overview ¶
Package output provides formatters for displaying test results.
Supported output formats:
- Console: Human-readable colored terminal output
- JSON: Machine-readable JSON output
- JUnit: JUnit XML format for CI integration
- TAP: Test Anything Protocol format
Each formatter implements the Formatter interface and can optionally implement Flushable for formats that accumulate results before output.
Index ¶
- type ConsoleFormatter
- type ConsoleOption
- type DiffResult
- type DiffType
- type HTMLAssertion
- type HTMLFormatter
- type HTMLOption
- type HTMLOutput
- type HTMLRequest
- type HTMLResponse
- type HTMLSummary
- type HTMLTest
- type JSONAssertion
- type JSONFormatter
- type JSONOption
- type JSONOutput
- type JSONRequest
- type JSONResponse
- type JSONSummary
- type JSONTest
- type JUnitError
- type JUnitFailure
- type JUnitFormatter
- type JUnitOption
- type JUnitSkipped
- type JUnitTestCase
- type JUnitTestSuite
- type JUnitTestSuites
- type TAPFormatter
- type TAPOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsoleFormatter ¶
type ConsoleFormatter struct {
// contains filtered or unexported fields
}
func NewConsoleFormatter ¶
func NewConsoleFormatter(opts ...ConsoleOption) *ConsoleFormatter
func (*ConsoleFormatter) FormatError ¶
func (f *ConsoleFormatter) FormatError(err error)
func (*ConsoleFormatter) FormatHeader ¶
func (f *ConsoleFormatter) FormatHeader(version string)
func (*ConsoleFormatter) FormatResult ¶
func (f *ConsoleFormatter) FormatResult(result *runner.RunResult)
type ConsoleOption ¶
type ConsoleOption func(*ConsoleFormatter)
func WithNoColor ¶
func WithNoColor(nc bool) ConsoleOption
func WithVerbose ¶
func WithVerbose(v bool) ConsoleOption
func WithWriter ¶
func WithWriter(w io.Writer) ConsoleOption
type DiffResult ¶ added in v1.2.1
DiffResult represents a single difference between expected and actual values.
type HTMLAssertion ¶ added in v1.2.0
type HTMLAssertion struct {
Subject string
Operator string
Expected any
Actual any
ExpectedStr string
ActualStr string
Passed bool
Message string
}
HTMLAssertion represents an assertion result for HTML output
type HTMLFormatter ¶ added in v1.2.0
type HTMLFormatter struct {
// contains filtered or unexported fields
}
HTMLFormatter formats test results as HTML
func NewHTMLFormatter ¶ added in v1.2.0
func NewHTMLFormatter(opts ...HTMLOption) *HTMLFormatter
NewHTMLFormatter creates a new HTML formatter
func (*HTMLFormatter) Flush ¶ added in v1.2.0
func (f *HTMLFormatter) Flush(totalDuration time.Duration) error
Flush writes the accumulated HTML output
func (*HTMLFormatter) FormatError ¶ added in v1.2.0
func (f *HTMLFormatter) FormatError(err error)
FormatError handles errors (no-op for HTML, errors are in test results)
func (*HTMLFormatter) FormatHeader ¶ added in v1.2.0
func (f *HTMLFormatter) FormatHeader(version string)
FormatHeader captures the version for the HTML report
func (*HTMLFormatter) FormatResult ¶ added in v1.2.0
func (f *HTMLFormatter) FormatResult(result *runner.RunResult)
FormatResult accumulates a test result
type HTMLOption ¶ added in v1.2.0
type HTMLOption func(*HTMLFormatter)
HTMLOption is a functional option for HTMLFormatter
func HTMLWithWriter ¶ added in v1.2.0
func HTMLWithWriter(w io.Writer) HTMLOption
HTMLWithWriter sets the output writer
type HTMLOutput ¶ added in v1.2.0
type HTMLOutput struct {
Version string
Summary HTMLSummary
Tests []HTMLTest
Duration float64
Time string
PassedPercent float64
FailedPercent float64
SkippedPercent float64
}
HTMLOutput represents the complete HTML output structure
type HTMLRequest ¶ added in v1.2.0
HTMLRequest represents request details for HTML output
type HTMLResponse ¶ added in v1.2.0
type HTMLResponse struct {
StatusCode int
Status string
Headers map[string]string
Duration float64
}
HTMLResponse represents response details for HTML output
type HTMLSummary ¶ added in v1.2.0
HTMLSummary represents the test summary for HTML output
type HTMLTest ¶ added in v1.2.0
type HTMLTest struct {
Name string
File string
Passed bool
Skipped bool
SkipReason string
Duration float64
Error string
StatusClass string
Request *HTMLRequest
Response *HTMLResponse
Assertions []HTMLAssertion
Captures map[string]any
}
HTMLTest represents a single test result for HTML output
type JSONAssertion ¶
type JSONAssertion struct {
Subject string `json:"subject"`
Operator string `json:"operator"`
Expected any `json:"expected"`
Actual any `json:"actual"`
Passed bool `json:"passed"`
Message string `json:"message,omitempty"`
}
JSONAssertion represents an assertion result
type JSONFormatter ¶
type JSONFormatter struct {
// contains filtered or unexported fields
}
JSONFormatter formats test results as JSON
func NewJSONFormatter ¶
func NewJSONFormatter(opts ...JSONOption) *JSONFormatter
func (*JSONFormatter) Flush ¶
func (f *JSONFormatter) Flush(totalDuration time.Duration) error
Flush writes the accumulated JSON output
func (*JSONFormatter) FormatError ¶
func (f *JSONFormatter) FormatError(err error)
func (*JSONFormatter) FormatHeader ¶
func (f *JSONFormatter) FormatHeader(version string)
func (*JSONFormatter) FormatResult ¶
func (f *JSONFormatter) FormatResult(result *runner.RunResult)
type JSONOption ¶
type JSONOption func(*JSONFormatter)
func JSONWithWriter ¶
func JSONWithWriter(w io.Writer) JSONOption
type JSONOutput ¶
type JSONOutput struct {
Summary JSONSummary `json:"summary"`
Tests []JSONTest `json:"tests"`
Duration float64 `json:"duration"`
Time string `json:"time"`
}
JSONOutput represents the complete JSON output structure
type JSONRequest ¶
type JSONRequest struct {
Method string `json:"method"`
URL string `json:"url"`
Headers map[string]string `json:"headers,omitempty"`
}
JSONRequest represents request details
type JSONResponse ¶
type JSONResponse struct {
StatusCode int `json:"statusCode"`
Status string `json:"status"`
Headers map[string]string `json:"headers,omitempty"`
Duration float64 `json:"duration"`
}
JSONResponse represents response details
type JSONSummary ¶
type JSONSummary struct {
Total int `json:"total"`
Passed int `json:"passed"`
Failed int `json:"failed"`
Skipped int `json:"skipped"`
}
JSONSummary represents the test summary
type JSONTest ¶
type JSONTest struct {
Name string `json:"name"`
File string `json:"file"`
Passed bool `json:"passed"`
Skipped bool `json:"skipped,omitempty"`
SkipReason string `json:"skipReason,omitempty"`
Duration float64 `json:"duration"`
Error string `json:"error,omitempty"`
Request *JSONRequest `json:"request,omitempty"`
Response *JSONResponse `json:"response,omitempty"`
Assertions []JSONAssertion `json:"assertions,omitempty"`
Captures map[string]any `json:"captures,omitempty"`
}
JSONTest represents a single test result
type JUnitError ¶
type JUnitError struct {
Message string `xml:"message,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
Content string `xml:",chardata"`
}
JUnitError represents a test error
type JUnitFailure ¶
type JUnitFailure struct {
Message string `xml:"message,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
Content string `xml:",chardata"`
}
JUnitFailure represents a test failure
type JUnitFormatter ¶
type JUnitFormatter struct {
// contains filtered or unexported fields
}
JUnitFormatter formats test results as JUnit XML
func NewJUnitFormatter ¶
func NewJUnitFormatter(opts ...JUnitOption) *JUnitFormatter
func (*JUnitFormatter) Flush ¶
func (f *JUnitFormatter) Flush(totalDuration time.Duration) error
Flush writes the accumulated JUnit XML output
func (*JUnitFormatter) FormatError ¶
func (f *JUnitFormatter) FormatError(err error)
func (*JUnitFormatter) FormatHeader ¶
func (f *JUnitFormatter) FormatHeader(version string)
func (*JUnitFormatter) FormatResult ¶
func (f *JUnitFormatter) FormatResult(result *runner.RunResult)
type JUnitOption ¶
type JUnitOption func(*JUnitFormatter)
func JUnitWithWriter ¶
func JUnitWithWriter(w io.Writer) JUnitOption
type JUnitSkipped ¶
type JUnitSkipped struct {
Message string `xml:"message,attr,omitempty"`
}
JUnitSkipped represents a skipped test
type JUnitTestCase ¶
type JUnitTestCase struct {
XMLName xml.Name `xml:"testcase"`
Name string `xml:"name,attr"`
ClassName string `xml:"classname,attr"`
Time float64 `xml:"time,attr"`
Failure *JUnitFailure `xml:"failure,omitempty"`
Error *JUnitError `xml:"error,omitempty"`
Skipped *JUnitSkipped `xml:"skipped,omitempty"`
}
JUnitTestCase represents a single test case
type JUnitTestSuite ¶
type JUnitTestSuite struct {
XMLName xml.Name `xml:"testsuite"`
Name string `xml:"name,attr"`
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Errors int `xml:"errors,attr"`
Skipped int `xml:"skipped,attr"`
Time float64 `xml:"time,attr"`
Timestamp string `xml:"timestamp,attr,omitempty"`
TestCases []JUnitTestCase `xml:"testcase"`
}
JUnitTestSuite represents a test suite (typically a file)
type JUnitTestSuites ¶
type JUnitTestSuites struct {
XMLName xml.Name `xml:"testsuites"`
Name string `xml:"name,attr,omitempty"`
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Errors int `xml:"errors,attr"`
Skipped int `xml:"skipped,attr"`
Time float64 `xml:"time,attr"`
Timestamp string `xml:"timestamp,attr,omitempty"`
TestSuites []JUnitTestSuite `xml:"testsuite"`
}
JUnitTestSuites is the root element
type TAPFormatter ¶
type TAPFormatter struct {
// contains filtered or unexported fields
}
TAPFormatter formats test results in TAP (Test Anything Protocol) format
func NewTAPFormatter ¶
func NewTAPFormatter(opts ...TAPOption) *TAPFormatter
func (*TAPFormatter) Flush ¶
func (f *TAPFormatter) Flush(totalDuration time.Duration) error
Flush writes the accumulated TAP output
func (*TAPFormatter) FormatError ¶
func (f *TAPFormatter) FormatError(err error)
func (*TAPFormatter) FormatHeader ¶
func (f *TAPFormatter) FormatHeader(version string)
func (*TAPFormatter) FormatResult ¶
func (f *TAPFormatter) FormatResult(result *runner.RunResult)