I have a relatively huge number of test cases. In case of failure, it takes time to go through all the log files and find the failed test cases. Is there any way in Catch2 to print the failed test cases?
Asked
Active
Viewed 821 times
1
-
https://github.com/catchorg/Catch2/blob/devel/docs/command-line.md#top – Eljay Nov 04 '21 at 00:45
-
@Eljay There is currently no command-line option that shows the only failed or successful test cases' names at the end of the reporter. – Emil Feb 11 '22 at 12:53
-
@Emil • Aww, drat. Sorry. (I switched from [Catch2](https://github.com/catchorg/Catch2) to [Doctest](https://github.com/doctest/doctest) several years ago. I like Catch2, and I like Doctest even better. For my needs, either one works better for me than Boost Test or GoogleTest.) – Eljay Feb 11 '22 at 13:44
-
Catch2 almost meets my needs, but at some point, simple features are lacking. Will try Doctest as well :) – Emil Feb 11 '22 at 13:49
1 Answers
0
You can create an EventListener and override testCaseEnded
to capture the names of the failed tests and testRunEnded
to print them out.
struct EventListener : Catch::TestEventListenerBase
{
using TestEventListenerBase::TestEventListenerBase;
void testCaseEnded(Catch::TestCaseStats const& testCaseStats) final
{
if (testCaseStats.totals.assertions.failed > 0)
{
// store failed test
}
}
void testRunEnded(Catch::TestRunStats const&) final
{
// print summary
}
};
CATCH_REGISTER_LISTENER(EventListener)

Dolphin
- 4,655
- 1
- 30
- 25