I have a C++ CMake project where I use Google Test for unit testing and I'm happy with the XML reports produced using ctest -T Test
. Now I would like to implement couple of integration tests that run specific application scenarios and expect a specific output e.g. running a C++ executable with default values should produce a specific output e.g. the following integration_test_01.sh
bash shell would be such a test:
#!/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
Is there a way to integrate such test with CMake or CTest and maybe even get some XML output?
With CMake and CTest you can add a test for my_algorithm
in the following way:
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")
The output of the command my_algorithm
will be checked against the specified regular expression and if the output does not match the test will fail.
When you run tests with ctest -T Test
the generated XML report will contain the actual output of the command nested in a <Measurement>
tag.