2017-03-07 153 views
4

我正在使用Qt Test来为某些计算繁重的算法编写单元测试。该工艺采用了大量的时间,并在较旧的计算机上运行时,该进程失败,因为像这样的超时:将超时设置为Qt测试

********* Start testing of KnotTest ********* 
Config: Using QtTest library 5.6.2, Qt 5.6.2 (i386-little_endian-ilp32 shared (dynamic) release build; by MSVC 2013) 
PASS : MyTest::initTestCase() 
QFATAL : MyTest::test_benchmark() Test function timed out 
FAIL! : MyTest::test_benchmark() Received a fatal error. 
Unknown file(0) : failure location 
Totals: 1 passed, 1 failed, 0 skipped, 0 blacklisted 
********* Finished testing of KnotTest ********* 

如何设置生成的测试程序的定制超时?

回答

2

您可以使用名为QTEST_FUNCTION_TIMEOUT的环境变量来覆盖超时。超时时间必须以毫秒为单位指定。默认情况下,Qt使用300000毫秒(5分钟)的超时。

这个环境变量没有记录,所以我不能保证它会继续存在于未来版本的Qt中。

顺便说一句,你可以使用qputenv编程设置环境变量:

http://doc.qt.io/qt-5/qtglobal.html#qputenv