4.7 使用超时测试运行时间过长的测试
准备工作
import sys
import time
# wait for 2 seconds
time.sleep(2)
# report success
sys.exit(0)具体实施
# set minimum cmake version cmake_minimum_required(VERSION 3.5 FATAL_ERROR) # project name project(recipe-07 LANGUAGES NONE) # detect python find_package(PythonInterp REQUIRED) # define tests enable_testing() # we expect this test to run for 2 seconds add_test(example ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.py)set_tests_properties(example PROPERTIES TIMEOUT 10)$ ctest Test project /home/user/cmake-recipes/chapter-04/recipe-07/example/build Start 1: example 1/1 Test #1: example .......................... Passed 2.01 sec 100% tests passed, 0 tests failed out of 1 Total Test time (real) = 2.01 sec$ ctest Test project /home/user/cmake-recipes/chapter-04/recipe-07/example/build Start 1: example 1/1 Test #1: example ..........................***Timeout 10.01 sec 0% tests passed, 1 tests failed out of 1 Total Test time (real) = 10.01 sec The following tests FAILED: 1 - example (Timeout) Errors while running CTest
工作原理
Last updated