纯新手编译gtest测试代码命令行分享(内含覆盖率)

这里被测试文件为:example.cpp,测试文件为test.cpp

首先进入代码所在目录,打开命令行:

1. 编译

clang++ -std=c++17 -fprofile-instr-generate -fcoverage-mapping example.cpp test.cpp -lgtest -lgtest_main -pthread -o test

2. 生成覆盖率数据

LLVM_PROFILE_FILE="test.profraw" ./test

3. 合并数据为可读格式

llvm-profdata merge -sparse test.profraw -o test.profdata

4. 终端直接查看源码级覆盖率(包含MC\DC覆盖率)

llvm-cov show ./test -instr-profile=test.profdata -show-branches=count --show-mcdc-summary

5. 终端直接查看文件级覆盖率

llvm-cov report ./test -instr-profile=test.profdata

6. 生成可视化报告

llvm-cov show -format=html -output-dir=coverage_report ./test -instr-profile=test.profdata --show-mcdc-summary

随后会在代码目录下有生成coverage_report文件夹,打开里面的index.html即可查看。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值