是否有一个框架来模拟对Qt应用程序施加的确定性伪随机系列点击 - 为了试图触发任何内存泄漏,线程错误等 - 典型的猴子测试?
一些奇特的,猴子用于QTestLib?
我正在Qt Creator中开发一个GUI应用程序,并希望为它编写一些单元测试.
我按照本指南使用QtTestlib进行了一些单元测试,程序编译得很好.但我如何运行它们?我希望它们在GUI应用程序启动之前运行,如果调试buid而不是在发布版本时运行.
我有一个不使用Qt的C++项目.我使用Qt Creator作为我的IDE,因为它非常方便.
我正在读关于Qt Creator的单元测试在这里,我认为Qt的测试似乎相当不错.有没有办法在我的非Qt C++项目中使用Qt Test?
请注意,我在我的PC中安装了Qt库,我正在使用它来编程.但我不希望我发布的编译程序依赖于Qt库.
此外,我在使用Visual Studio时喜欢的一个功能是每次构建项目时都会自动运行测试.我可以用Qt Creator做同样的事吗?
顺便说一句,如果你可以建议我可以在Qt Creator中轻松使用的另一个单元测试框架,那也没关系.
我有一个比较两个字符串值的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)