This project provides CMake functions to simplify running C++ tests with code coverage reports generated by OpenCppCoverage.
In order to use cpp-coverage
to simplify usage of OpenCppCoverage, all you need
to do is to make sure cpp-coverage
is available to your build by e.g.
FetchContent
or ExternalProject_Add
followed by add_subdirectory
and finally use cpp_coverage_add_test
function to augment the regular cmake
add_test
function with coverage measurements based on existing test binary targets.
The utility functions provided by this repository will create custom targets to generate
generate coverage reports (e.g. HTML) based on merged .cov files generated while
running CTest
. Coverage reports default to aggregated project coverage but additional
options exist to for example generate reports per test target or aggregate a global
"super-build" coverage report.
See documentation of CMake functions in cmake/cpp_coverage.cmake for a complete list of supported options.
See documentation of ReportGenerator for
documentation on how to customize coverage reports outside what is supported by OpenCppCoverage.
ReportGenerator is activated by setting CPP_COVERAGE_ENABLE_REPORT_GENERATOR
to ON
.
Examples provided in this project are using Google Test in combination with CTest but
also showcases usage with custom solutions.
Note that CTest support is similar to CMake add_test
command.
Adding tests via e.g. gtest_discover_tests(...)
is currently not supported but might
be added in the future.
For complete examples, see examples folder. Examples are not built by default
and requires CPP_COVERAGE_BUILD_EXAMPLES
to be set to ON
.
See OpenCppCoverage documentation for details on how to use and integrate in CI etc.
This project is released under the MIT license, see LICENSE. This basically means you can do whatever you want with this project as long as you provide the original license and copyright information with your own project distribution.
Note that utilized dependencies such as OpenCppCoverage, Google Test and ReportGenerator are subject of their respective licenses and terms and are not distributed as part of this software.