使用lcov对.cpp文件进行unitest时,排除头文件的覆盖范围 [英] Exclude the header files coverage while doing the unitests for .cpp files using lcov
问题描述
我已经为单元测试生成了html代码覆盖率.问题在于,它会为包含预处理器中定义的所有内容生成代码覆盖率.
I have generated the html code coverage for unittest. The problem is that it generates the code coverage for everything that is defined in the include preprocessor.
单元测试的代码覆盖率位于代码覆盖率报告的 unitTest 链接内.我只需要 unitTest
The codecoverage for the unittest is inside the unitTest link of the code coverage report. I only need the unitTest
在生成代码覆盖率之前,我还删除了所有其他内容并保留了测试文件的gcda和gcno文件,但这仍然无济于事.这样做的代码是:
I also remove everything else and keep the gcda and gcno files of the test file before generating the code coverage but it still doesnot help. The code that does this is :
find obj/ ! -name '*_unittests*' -type f -delete
代码覆盖率报告如下所示:
The code coverage report is show below :
我尝试在包含预处理器的开头和结尾处添加LCOV_EXCL_START和LCOV_EXCL_STOP,如下所示,但这仍然无济于事.
I tried to add LCOV_EXCL_START and LCOV_EXCL_STOP at the beginning and end of include preprocessors as follows but it still doesnot help.
LCOV_EXCL_START
#include <inttypes.h>
#include "../src/generators/buffersss.h"
#include "gtest/gtest.h"
#include <getopt.h>
LCOV_EXCL_STOP
Test code goes here.....
我在这里做错什么了?
推荐答案
以下代码解决了该问题
lcov --remove coverage.info '/usr/include/*' 'src/*' -o filtered_coverage.info
这篇关于使用lcov对.cpp文件进行unitest时,排除头文件的覆盖范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!