Pigweed
 
Loading...
Searching...
No Matches
pw::unit_test::TestRecordEventHandler Class Reference

#include <test_record_event_handler.h>

Inheritance diagram for pw::unit_test::TestRecordEventHandler:
pw::unit_test::EventHandler

Public Member Functions

 TestRecordEventHandler (int64_t seconds_since_epoch)
 
void TestCaseEnd (const TestCase &test_case, TestResult result) override
 
void RunAllTestsEnd (const RunTestsSummary &summary) override
 
void TestCaseExpect (const TestCase &test_case, const TestExpectation &expectation) override
 
std::string GetTestRecordJsonString (size_t max_json_buffer_size, bool failing_results_only=false)
 
void RunAllTestsStart () override
 Called before all tests are run.
 
void TestProgramStart (const ProgramSummary &) override
 Called before any test activity starts.
 
void EnvironmentsSetUpEnd () override
 Called after environment setup for each iteration of tests ends.
 
void TestSuiteStart (const TestSuite &) override
 Called before the test suite starts.
 
void TestSuiteEnd (const TestSuite &) override
 Called after the test suite ends.
 
void EnvironmentsTearDownEnd () override
 Called after environment teardown for each iteration of tests ends.
 
void TestProgramEnd (const ProgramSummary &) override
 Called after all test activities have ended.
 
void TestCaseStart (const TestCase &) override
 Called when a new test case is started.
 
void TestCaseDisabled (const TestCase &) override
 Called when a disabled test case is encountered.
 
virtual void TestProgramStart (const ProgramSummary &program_summary)=0
 Called before any test activity starts.
 
virtual void EnvironmentsSetUpEnd ()=0
 Called after environment setup for each iteration of tests ends.
 
virtual void TestSuiteStart (const TestSuite &test_suite)=0
 Called before the test suite starts.
 
virtual void TestSuiteEnd (const TestSuite &test_suite)=0
 Called after the test suite ends.
 
virtual void EnvironmentsTearDownEnd ()=0
 Called after environment teardown for each iteration of tests ends.
 
virtual void TestProgramEnd (const ProgramSummary &program_summary)=0
 Called after all test activities have ended.
 
virtual void RunAllTestsStart ()=0
 Called before all tests are run.
 
virtual void RunAllTestsEnd (const RunTestsSummary &run_tests_summary)=0
 Called after all tests are run.
 
virtual void TestCaseStart (const TestCase &test_case)=0
 Called when a new test case is started.
 
virtual void TestCaseEnd (const TestCase &test_case, TestResult result)=0
 
virtual void TestCaseDisabled (const TestCase &)
 Called when a disabled test case is encountered.
 
virtual void TestCaseExpect (const TestCase &test_case, const TestExpectation &expectation)=0
 

Detailed Description

Predefined event handler implementation that outputs a test record (or summary) in Chromium JSON Test Results Format. To use it, register the event handler, call the RUN_ALL_TESTS macro, then extract the test record json as a string using the GetTestRecordJsonString method. If you only want to extract the failing tests, set the failing_results_only parameter to true. See pw::unit_test::EventHandler for explanations of emitted events.

See also
https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/testing/json_test_results_format.md
Warning
This event handler uses dynamic allocation (new/delete/std::string) to generate the test record json.

Constructor & Destructor Documentation

◆ TestRecordEventHandler()

pw::unit_test::TestRecordEventHandler::TestRecordEventHandler ( int64_t  seconds_since_epoch)
inline

Constructor for the event handler. Have to seconds_since_epoch since calling std::time(nullptr) in pigweed is not supported.

Parameters
[in]seconds_since_epochSeconds since epoch. Used in the test record as the seconds since epoch for the start of the test run.

Member Function Documentation

◆ EnvironmentsSetUpEnd()

void pw::unit_test::TestRecordEventHandler::EnvironmentsSetUpEnd ( )
inlineoverridevirtual

Called after environment setup for each iteration of tests ends.

Implements pw::unit_test::EventHandler.

◆ EnvironmentsTearDownEnd()

void pw::unit_test::TestRecordEventHandler::EnvironmentsTearDownEnd ( )
inlineoverridevirtual

Called after environment teardown for each iteration of tests ends.

Implements pw::unit_test::EventHandler.

◆ GetTestRecordJsonString()

std::string pw::unit_test::TestRecordEventHandler::GetTestRecordJsonString ( size_t  max_json_buffer_size,
bool  failing_results_only = false 
)
inline

Converts the test record trie into a json string and returns it.

Parameters
[in]max_json_buffer_sizeThe max size (in bytes) of the buffer to allocate for the json string.
[in]failing_results_onlyIf true, the outputted test record will only contain the failing tests.
Returns
The test record json as a string.

◆ RunAllTestsEnd()

void pw::unit_test::TestRecordEventHandler::RunAllTestsEnd ( const RunTestsSummary summary)
inlineoverridevirtual

Called after all tests are run. Save the run tests summary for later use.

Parameters
[in]summaryA test run summary. Contains counts of each test result type.

Implements pw::unit_test::EventHandler.

◆ RunAllTestsStart()

void pw::unit_test::TestRecordEventHandler::RunAllTestsStart ( )
inlineoverridevirtual

Called before all tests are run.

Implements pw::unit_test::EventHandler.

◆ TestCaseDisabled()

void pw::unit_test::TestRecordEventHandler::TestCaseDisabled ( const TestCase )
inlineoverridevirtual

Called when a disabled test case is encountered.

Reimplemented from pw::unit_test::EventHandler.

◆ TestCaseEnd()

void pw::unit_test::TestRecordEventHandler::TestCaseEnd ( const TestCase test_case,
TestResult  result 
)
inlineoverridevirtual

Called when a test case completes. Record the test case result in the test record trie.

Parameters
[in]test_caseTest case that ended.
[in]resultResult of the test case.

Implements pw::unit_test::EventHandler.

◆ TestCaseExpect()

void pw::unit_test::TestRecordEventHandler::TestCaseExpect ( const TestCase test_case,
const TestExpectation expectation 
)
inlineoverridevirtual

Called after each expect/assert statement within a test case with the result of the expectation.

We usually expect all tests to PASS. However, if the GTEST_SKIP macro is used, the test is expected to be skipped and the expectation expression is replaced with "(test skipped)"

Parameters
[in]test_caseTest case that the expect statement lies in.
[in]expectationCurrent expectation being checked for the test case.

Implements pw::unit_test::EventHandler.

◆ TestCaseStart()

void pw::unit_test::TestRecordEventHandler::TestCaseStart ( const TestCase test_case)
inlineoverridevirtual

Called when a new test case is started.

Implements pw::unit_test::EventHandler.

◆ TestProgramEnd()

void pw::unit_test::TestRecordEventHandler::TestProgramEnd ( const ProgramSummary program_summary)
inlineoverridevirtual

Called after all test activities have ended.

Implements pw::unit_test::EventHandler.

◆ TestProgramStart()

void pw::unit_test::TestRecordEventHandler::TestProgramStart ( const ProgramSummary program_summary)
inlineoverridevirtual

Called before any test activity starts.

Implements pw::unit_test::EventHandler.

◆ TestSuiteEnd()

void pw::unit_test::TestRecordEventHandler::TestSuiteEnd ( const TestSuite test_suite)
inlineoverridevirtual

Called after the test suite ends.

Implements pw::unit_test::EventHandler.

◆ TestSuiteStart()

void pw::unit_test::TestRecordEventHandler::TestSuiteStart ( const TestSuite test_suite)
inlineoverridevirtual

Called before the test suite starts.

Implements pw::unit_test::EventHandler.


The documentation for this class was generated from the following file: