【问题标题】:Printing failed test case names in Catch2在 Catch2 中打印失败的测试用例名称
【发布时间】:2021-11-04 00:40:35
【问题描述】:

我有大量的测试用例。在失败的情况下,需要时间来遍历所有日志文件并找到失败的测试用例。 Catch2 中有没有办法打印失败的测试用例?

【问题讨论】:

  • @Eljay 目前没有命令行选项在报告器末尾显示唯一失败或成功的测试用例名称。
  • @Emil • 哇,废话。对不起。 (几年前我从Catch2 切换到Doctest。我喜欢Catch2,我更喜欢Doctest。根据我的需要,任何一个都比Boost Test 或GoogleTest 更适合我。)
  • Catch2 几乎可以满足我的需求,但在某些时候,缺少简单的功能。也会尝试 Doctest :)

标签: c++ catch2


【解决方案1】:

您可以创建 EventListener 并覆盖 testCaseEnded 以捕获失败测试的名称,并使用 testRunEnded 将其打印出来。

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)

【讨论】:

    猜你喜欢
    • 2020-01-06
    • 2013-07-14
    • 2016-12-22
    • 2017-02-21
    • 1970-01-01
    • 2013-06-25
    • 2015-12-08
    • 2011-12-09
    • 1970-01-01
    相关资源
    最近更新 更多