2017-03-07 82 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