bash - 使用 bash 与 CMake 和 CTest 进行简单的集成测试?

标签 bash cmake integration-testing ctest

我有一个 C++ CMake 项目,在其中使用 Google Test 进行单元测试,并且我对使用 ctest -T Test 生成的 XML 报告感到满意。现在我想实现几个集成测试,运行特定的应用程序场景并期望特定的输出,例如使用默认值运行 C++ 可执行文件应该会产生特定的输出,例如下面的 integration_test_01.sh bash shell 就是这样一个测试:

 #!/bin/bash
 ./my_algorithm > out && grep "mse\=1\.2345e\-6" out 
 if [ $? == 0 ]; then
     echo "integration test succeeded"
 else
     echo "integration test failed" >&2
 fi
 rm out | cat

有没有办法将此类测试与 CMake 或 CTest 集成,甚至可能获得一些 XML 输出?

最佳答案

使用 CMake 和 CTest,您可以添加 my_algorithm 的测试通过以下方式:

add_executable(my_algorithm ...)
add_test(NAME integration_test_01 COMMAND my_algorithm)
set_tests_properties(integration_test_01 
    PROPERTIES PASS_REGULAR_EXPRESSION "mse\\=1\\.2345e\\-6")

命令的输出 my_algorithm将根据指定的正则表达式进行检查,如果输出不匹配,则测试将失败。

当您使用 ctest -T Test 运行测试时生成的 XML 报告将包含嵌套在 <Measurement> 中的命令的实际输出。标签。

关于bash - 使用 bash 与 CMake 和 CTest 进行简单的集成测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19435375/

相关文章:

python - python 脚本上的 sed 替换 - "command not found"问题

linux - 使用 bash 通配符定位行为

c++ - 如何包含 VS 2008 的 Boost 库(命令行)

linux - 如何使用 telnet 获取外部连接的 IP,或者可能是 memcached 允许的 ip 的配置错误

linux - rc.d 脚本默认给出 "start"参数?

cmake - 使用 CMake 生成文件并将其添加为可执行文件

c++ - CMake 更改强制 DESTINATION 目录名称(安装目标)

integration-testing - 如何将本地 DynamoDB 与 AWS Go SDK 结合使用?

java - 自动化集成测试 : Use xUnit?

playframework - 与 Play 框架的集成测试,不使用夹具