QTest执行两次测试用例
QTest executes test case twice
我在QTest中编写了一个小的基准测试,尽管我使用了QBENCHMARK_ONCE。
这里有一些复制问题的示例代码:
标题:
#ifndef MY_TEST_H
#define MY_TEST_H
#include <QtTest>
class MyTest : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void test1();
};
#endif // MY_TEST_H
cpp文件:
#include "mytest.h"
void MyTest::initTestCase() {
qDebug() << "init";
}
void MyTest::test1() {
QBENCHMARK_ONCE {
qDebug() << "bench";
}
qDebug() << "test1";
}
QTEST_MAIN(MyTest)
运行"mytest"我得到:
********* Start testing of MyTest *********
Config: Using QtTest library 5.5.1, Qt 5.5.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160407)
QDEBUG : MyTest::initTestCase() init
PASS : MyTest::initTestCase()
QDEBUG : MyTest::test1() bench
QDEBUG : MyTest::test1() test1
QDEBUG : MyTest::test1() bench
QDEBUG : MyTest::test1() test1
PASS : MyTest::test1()
RESULT : MyTest::test1():
0 msecs per iteration (total: 0, iterations: 1)
PASS : MyTest::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of MyTest *********
我希望它只运行一次。有些基准测试每次迭代需要一分钟。。。
我在Linux上使用带有make后端的CMake。它们测试类被编译成单独的可执行文件。由于ctest没有给我有用的输出,我直接运行它们,即"#./mytest"
//添加:CMakeLists.txt
include(CTest)
enable_testing()
set(CMAKE_AUTOMOC ON)
find_package(Qt5Test REQUIRED)
add_executable(mytest "test/mytest.cpp")
add_test(mytest mytest)
target_link_libraries(mytest Qt5::Test)
显然,这是为了减轻初始化和缓存对结果的影响:
https://bugreports.qt.io/browse/QTBUG-12689
不过,我认为他们应该将其添加到文档中。或者给宏命名不那么令人困惑。
相关文章:
- pybind11 运行测试用例
- GTest,仅参数化测试用例
- 如何使用不同的谷歌模拟运行相同的谷歌测试用例?
- 请找出我的代码中的错误,它在提交得到错误答案的同时仍然适用于我的所有测试用例
- 如何使用值模板编写文档测试用例?
- 用于查找最低共同祖先的代码不适用于某些测试用例
- 为什么给定的代码不适用于所有测试用例?为什么当输入为 7786 时它不起作用?
- GTest - 在不同的参数上运行多个测试用例
- 如何创建演示 /EH 成本的最小测试用例?
- 查找在 4 和问题中代码失败的测试用例
- 如何编写在函数执行过程中垃圾回收的测试用例?
- 括号检查器完美地适用于单个测试用例,但对于所有测试用例,它给出了分段错误?
- 我已经通过了该问题的所有测试用例,甚至是Udebugg上的所有测试用例,并且仍然在UVA在线法官上获得了WA裁决
- 如何使用参数化测试用例
- 相同的测试用例,但代码块和Ideone的输出不同
- 在老板层次结构中查找"top"老板仅适用于某些测试用例
- Eclipse 项目中的 OSCPack 外部库测试用例
- 每次使用不同的fixture多次执行一个测试用例
- QTest执行两次测试用例
- 在升压测试中多次重复测试用例