将超时设置为 Qt 测试 [英] Setting timeout to Qt Test

查看:38
本文介绍了将超时设置为 Qt 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Qt 测试,为一些计算繁重的算法编写单元测试.该进程使用了​​相当多的时间,并且在较旧的计算机上运行时,该进程会因为超时而失败,如下所示:

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?

推荐答案

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

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).

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

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

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

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

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

这篇关于将超时设置为 Qt 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆