【发布时间】:2013-07-27 07:42:00
【问题描述】:
我正在使用 CMake 开发一个项目,并且刚刚集成了一些 CppUnit 测试。我想使用 CTest,因此我在 CMakeLists.txt 文件中使用了 add_test,以便在键入 make test 时执行测试。
然而我观察到,当输入make test 时,它表示所有测试都通过了,即使我进行了一个有微不足道的测试。错误的测试在手动执行时会报告这些错误(例如 ./my_test),但在使用 make test 执行时不会报告这些错误。
这里是我的 CMakeLists.txt 在测试目录中的内容:
add_executable(TestDataSpace TestDataSpace.cpp)
target_link_libraries(TestDataSpace ${DEP_LIBRARIES} ${CPPUNIT_LIBRARIES})
add_executable(TestVariableManager TestVariableManager.cpp)
target_link_libraries(TestVariableManager ${DEP_LIBRARIES} ${CPPUNIT_LIBRARIES})
add_executable(TestLayoutManager TestLayoutManager.cpp)
target_link_libraries(TestLayoutManager ${DEP_LIBRARIES} ${CPPUNIT_LIBRARIES})
add_test(NAME "TestDataSpace" COMMAND ${MY_PROJECT_SOURCE_DIR}/test/TestDataSpace)
add_test(NAME "TestVariableManager" COMMAND ${MY_PROJECT_SOURCE_DIR}/test/TestVariableManager)
add_test(NAME "TestLayoutManager" COMMAND ${MY_PROJECT_SOURCE_DIR}/test/TestLayoutManager)
CTest 确实找到了可执行文件,因为为命令设置了错误的路径会使 CMake 抱怨它找不到它们。
make test 输出以下内容:
运行测试...测试项目
Start 1: TestDataSpace 1/3 Test #1: TestDataSpace .................... Passed 0.01 sec Start 2: TestVariableManager 2/3 Test #2: TestVariableManager .............. Passed 0.02 sec Start 3: TestLayoutManager 3/3 Test #3: TestLayoutManager ................ Passed 0.01 sec100% 测试通过,3 次测试中有 0 次失败
我错过了什么?
【问题讨论】: