我有一个比较两个字符串值的QtTest:
// This definitely returns "5/6"
std::string actual_value = simple(actual);
// Sets a string to the expected value
std::string expected_value = "5/6";
然后是QCOMPARE:
QCOMPARE(QString(actual_value.c_str()), QString(expected_value.c_str()));
/* I'm Aware this could just be the code below (but this doesnt print values to
console so i can check they are actually the same) */
QCOMPARE(actual_value, expected_value)
我得到了错误:(生病后两者都明显不仅仅是QString失败了,所以下面是使用QString显示值的QCOMPARE)
FAIL! : TestFraction::testFraction() Compared values are not the same
Actual (QString(actual_value.c_str())): 5/6
Expected (QString(expected_value.c_str())): 5/6
这是正常的QCOMPARE错误消息:
FAIL! : TestFraction::testFraction() Compared values are not the same
显然还有其他代码,但我现在不发布它,因为我不认为它特别相关,但问你是否想知道你想知道的东西,只要我能看到这个测试应该通过但也许是我不知道的东西关于比较字符串(比如比较双精度失败,除非你使用模糊比较)
提前致谢
答案 0 :(得分:6)
您的实际字符串有一个换行符。因此比较失败。