我使用的是只在外部资源可用的情况下才运行测试所需的CMake参数。但是,外部资源是可选的(在某些测试机器上可用,而在其他测试机器上可用),所以当检查资源的夹具失败时,我不想认为测试套件失败了,我只是不想运行任何需要该夹具的测试。是否有方法将测试夹具标记为“允许失败”。我知道有WILL_FAIL,但是这与测试的意义相反,这样当它通过测试时,它就会被标记为失败。
发布于 2019-03-13 19:08:29
不是的。当您添加测试时,意味着您希望该测试通过。当该测试的先决条件失败时,CMake跳过该测试(实际上并不运行它),并将其视为失败,因为它没有成功。
例如:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(example)
enable_testing()
add_test(NAME failIfUnavail COMMAND false)
add_test(NAME dependentTest1 COMMAND true)
add_test(NAME dependentTest2 COMMAND true)
add_test(NAME cleaner COMMAND true)
set_tests_properties(failIfUnavail PROPERTIES FIXTURES_SETUP example_case)
set_tests_properties(dependentTest1 dependentTest2 PROPERTIES FIXTURES_REQUIRED example_case)
set_tests_properties(cleaner PROPERTIES FIXTURES_CLEANUP example_case)$ cmake -H. -Bbuild
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /bin/gcc
-- Check for working C compiler: /bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /bin/g++
-- Check for working CXX compiler: /bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /build
$ cmake --build build/ --target test
Running tests...
Test project /home/pamini/cmake_test1/build
Start 1: failIfUnavail
1/4 Test #1: failIfUnavail ....................***Failed 0.00 sec
Start 2: dependentTest1
Failed test dependencies: failIfUnavail
2/4 Test #2: dependentTest1 ...................***Not Run 0.00 sec
Start 3: dependentTest2
Failed test dependencies: failIfUnavail
3/4 Test #3: dependentTest2 ...................***Not Run 0.00 sec
Start 4: cleaner
4/4 Test #4: cleaner .......................... Passed 0.00 sec
25% tests passed, 3 tests failed out of 4
Total Test time (real) = 0.02 sec
The following tests FAILED:
1 - failIfUnavail (Failed)
2 - dependentTest1 (Not Run)
3 - dependentTest2 (Not Run)
Errors while running CTest
gmake: *** [test] Error 8你能做的是:
https://stackoverflow.com/questions/51964655
复制相似问题