TTS v3.0.0
The Tiny Test System
Loading...
Searching...
No Matches

output_sink rendering the run as JUnit XML, the de facto standard consumed by Jenkins, GitLab CI, CircleCI, Azure DevOps, Bitbucket Pipelines and most CI dashboards. More...

Detailed Description

output_sink rendering the run as JUnit XML, the de facto standard consumed by Jenkins, GitLab CI, CircleCI, Azure DevOps, Bitbucket Pipelines and most CI dashboards.

Built from output_sink's structured hooks rather than by parsing the human-readable text tts::stdout_sink prints, so it stays correct regardless of -v/-q. Every TTS_CASE becomes one <testcase> (name, classname, elapsed time in seconds) inside a single <testsuite>, with a <skipped/> child for an invalid case or a <failure> child gathering every failing assertion's message for a failed one. Rendered by dump(), or automatically via finish(), to the target given at construction (tts::output_handler::default_sink() by default). It does not (currently) reflect TTS_CASE_TPL's per-type breakdown or TTS_WHEN / TTS_AND_THEN sub-scenarios, since those don't have their own hook - only the enclosing TTS_CASE does.

Example

tts::output().sink(junit);
// ... run the test suite ...
junit.dump(); // stream the JUnit XML report to stdout
void sink(output_sink &s)
Installs s as the output_sink every subsequent write goes to.
Definition output.hpp:379
output_handler & output()
Retrieves the current TTS output_handler.
Definition output.hpp:414
output_sink rendering the run as JUnit XML, the de facto standard consumed by Jenkins,...
Definition junit.hpp:70
void dump(output_sink &target)
Forwards the JUnit-rendered report to target, then clears the gathered results.
Definition junit.hpp:159

Public Member Functions

void assertion_failed (text const &location, text const &message, bool fatal) override
void clear ()
 Discards everything gathered so far.
void dump ()
 Streams the JUnit-rendered report to stdout, then clears the gathered results.
void dump (output_sink &target)
 Forwards the JUnit-rendered report to target, then clears the gathered results.
void finish () override
 Dumps the JUnit-rendered report to the target given at construction.
virtual void flush ()
 Flushes this sink's destination, if that means anything for it. No-op by default.
text render () const
 Renders everything gathered so far as a single JUnit XML document.
virtual void suite_aborted ()
virtual void suite_finished (unsigned long long fail_count, unsigned long long invalid_count)
virtual void suite_metric (outcome kind, unsigned long long count, unsigned long long total)
void test_finished (text const &name, bool passed, bool invalid, unsigned long long duration_ns) override
virtual void test_started (text const &name)
void write (text const &) override
 Writes t to this sink's destination.

Member Function Documentation

◆ assertion_failed()

void tts::junit_sink::assertion_failed ( text const & location,
text const & message,
bool fatal )
inlineoverridevirtual

Called once per failing/fatal assertion, always and before the corresponding text (if any - it's suppressed under -q for a plain failure, though never for a fatal one). No-op by default. Not called for passing assertions - test_finished()'s passed already covers that case, and most consumers of this hook don't want one event per assertion.

Reimplemented from tts::output_sink.

◆ suite_aborted()

virtual void tts::output_sink::suite_aborted ( )
inlinevirtualinherited

Called if the suite aborts early due to a TTS_FATAL failure, before tts::report() (and thus suite_finished()) runs. No-op by default.

Reimplemented in tts::colorized_sink.

◆ suite_finished()

virtual void tts::output_sink::suite_finished ( unsigned long long fail_count,
unsigned long long invalid_count )
inlinevirtualinherited

Called once the whole suite has finished running (from tts::report()), with its aggregate outcome, always - even under -q. No-op by default.

Reimplemented in tts::colorized_sink.

◆ suite_metric()

virtual void tts::output_sink::suite_metric ( outcome kind,
unsigned long long count,
unsigned long long total )
inlinevirtualinherited

Called once per non-zero outcome category, right before its "N/M (P%) <label>" segment is printed as part of the Results: ... summary. No-op by default.

Reimplemented in tts::colorized_sink.

◆ test_finished()

void tts::junit_sink::test_finished ( text const & name,
bool passed,
bool invalid,
unsigned long long duration_ns )
inlineoverridevirtual

Called once a TTS_CASE / TTS_CASE_TPL / TTS_CASE_WITH has finished running, always and before its corresponding text (if any - suppressed under -q), with its outcome and how long it took to run, in nanoseconds. No-op by default.

Reimplemented from tts::output_sink.

◆ test_started()

virtual void tts::output_sink::test_started ( text const & name)
inlinevirtualinherited

Called when a TTS_CASE / TTS_CASE_TPL / TTS_CASE_WITH is about to run. No-op by default - opt-in for sinks that want structured per-test events instead of (or in addition to) parsing the formatted text stream.

Reimplemented in tts::colorized_sink.