I just wonder, is there a way to track which test/test_suite is started/stopped to log that event into my log file so I know in the log file which events correspond to which test.
From the very beginning I just added a line to the test case like following. And it worked fine.
BOOST_AUTO_TEST_CASE(testRecovery)
{
SPDLOG_INFO("MyComponentTests::testRecovery");
// ...
Once I've reached 20+ tests cases it became hard to manage that approach. I've started to forgetting to add that line. Also this approach suffers from copy-paste errors. Also in case if I change the test name, it is easy to forget to update the log record.
Later I've found boost::unit_test::unit_test_log_formatter
and I've created a TestCasesTracker
class that does a job:
class TestCasesTracker : public boost::unit_test::unit_test_log_formatter
{
void test_unit_start(std::ostream&, boost::unit_test::test_unit const& tu) override
{
// ...
SPDLOG_INFO("==> {}", tu.p_name);
Unfortunately this approach does not work for me, as it completely takes over all the logging so --log_level=test_suite
does not work. Also I used that approach to integrate my tests into the TeamCity. So when I enable my TestCasesTracker
, TeamCity becomes blind on which tests are executed.
Another idea maybe to create a log file per test case. I afraid I'm gonna have too many log files. And still it is not clear which log file corresponds to which test case.
Therefore my question, is there non-intrusive way to catch test start/stop events?
Maybe I should implement the composite of the original boost test formatter and TeamCity logger...