我使用Catch2作为Unittest。我要在构建后进行测试。
所以我在Catch中使用'cath_discover_test‘函数。
但是在构建的时候,不要打印任何关于测试的内容。
如下所示:
> cmake --build .
blah ~
blah ~
PostBuildEvent:
setlocal
"C:\Program Files\CMake\bin\cmake.exe" -D TEST_TARGET=foo -D TEST_EXECUTABLE=C:/Users/MyName/workspace/someproject/build/
Debug/foo.exe -D TEST_EXECUTOR= -D TEST_WORKING_DIR=C:/Users/MyName/workspace/someproject/build -D TEST_SPEC= -D TEST_EXT
RA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX= -D TEST_SUFFIX= -D TEST_LIST=foo_TESTS -D CTEST_FILE=C:/Users/MyName/workspace/a
someproject/build/foo_tests-b858cb2.cmake -P "C:/Program Files (x86)/Catch2/lib/cmake/Catch2/CatchAddTests.cmake"
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd
blah ~
blah ~
end这是test.cmake文件源代码:
find_package(Catch2 REQUIRED)
add_executable(foo ${PROJECT_SOURCE_DIR}/test/test.cpp)
target_include_directories(foo PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(foo Catch2::Catch2)
include(CTest)
include(Catch)
catch_discover_tests(foo)但是,我通过ctest像下面这样执行测试,测试工作。
>ctest
Test project C:/Users/MyNames/workspace/someproject/build
Start 1: some class test
1/1 Test #1: some class test .............***Failed 0.02 sec
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.04 sec
The following tests FAILED:
1 - some class test (Failed)
Errors while running CTest如何在生成后运行测试并显示测试结果的输出?
发布于 2019-01-27 23:11:44
CMake并不期望您在构建的同时运行测试。您可以想象一个跨编译器的情况,在这种情况下,目标体系结构与您的主机构建机器不一样,在这种情况下,在构建时运行测试是没有意义的。
我希望将构建的测试作为CMake构建的一部分运行,查看add_custom_command以运行POST_BUILD命令。
https://stackoverflow.com/questions/54388883
复制相似问题