cppunit 导出局部变量

cppunit export local variable

for (int i = 0; i < 50; ++i)
    {
        CPPUNIT_ASSERT(RtcTime_GetDayOfWeek(TimeC[i])==RtcTime_GetDayOfWeek(TimeC[i+1]));
    }

这次考试倒下了。我如何导出此测试失败的 'i'?

现在我的输出

1) test: testEq (F) line: 55 rtc_test.cxx
assertion failed
- Expression: RtcTime_GetDayOfWeek(TimeC[i])==RtcTime_GetDayOfWeek(TimeC[i+1])

我想要那样的东西

1) test: testEq (F) line: 55 rtc_test.cxx
    assertion failed
    - Expression: RtcTime_GetDayOfWeek(TimeC[i])==RtcTime_GetDayOfWeek(TimeC[i+1])
i=49

你可以这样做,它会在 CppUnit 断言时打印一条消息。

for (int i = 0; i < 50; ++i)
{
    std::stringstream oss;
    oss << "testing RtcTime_GetDayOfWeek(TimeC[i]) where i=" << i << std::endl;
    CPPUNIT_ASSERT_MESSAGE(oss.str(),
              RtcTime_GetDayOfWeek(TimeC[i])==RtcTime_GetDayOfWeek(TimeC[i+1]));
}