Setting timeout to Qt Test

跟風遠走 提交于 2019-12-21 16:59:03

问题


I'm using Qt Test, for write unit tests for some computing heavy algorithms. The process uses a considerable amount of time, and when is run in a older computer, the process fails because a timeout like this:

********* 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 *********

How can set a custom timeout for the test program generated?


回答1:


You can override the timeout using an environment variable called QTEST_FUNCTION_TIMEOUT. The timeout must be specified in milliseconds. By default, Qt uses a timeout of 300000 milliseconds (5 minutes).

This environment variable is undocumented, so I can't guarantee that it will continue to be present in future versions of Qt.

As an aside, you can programmatically set environment variables using qputenv:

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




回答2:


In QtCreator you can change the default timeout in

Tools -> Options -> Testing -> General : Timeout

See also "Building and Running Tests" in the following link:

http://doc.qt.io/qtcreator/creator-autotest.html



来源:https://stackoverflow.com/questions/42655932/setting-timeout-to-qt-test

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!