我有一个比较两个字符串值的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";
Run Code Online (Sandbox Code Playgroud)
然后是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)
Run Code Online (Sandbox Code Playgroud)
我得到了错误:(生病后两者所以很明显它不仅仅是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
Run Code Online (Sandbox Code Playgroud)
这是正常的QCOMPARE错误消息:
FAIL! : TestFraction::testFraction() Compared values are not the same
Run Code Online (Sandbox Code Playgroud)
显然还有其他代码,但我现在不发布它,因为我不认为它特别相关,但问你是否想知道你想知道的东西,只要我能看到这个测试应该通过但也许我不知道有关比较字符串的东西(比较如何比较双打失败,除非你使用模糊比较)
提前致谢
| 归档时间: |
|
| 查看次数: |
1264 次 |
| 最近记录: |