我发现了一些工具,可以在运行单元测试或由
grcov
触发时为 Rust 代码生成代码覆盖率报告(如 tarpaulin
、llvm-cov
、kcov
和 cargo
)。
但在我们的例子中,我们有远程 python 测试,它们与用 Rust 编写的远程服务器进行交互。我如何检测和收集此类覆盖率报告?
我们有一个类似的解决方案,我们使用基于 LLVM 源代码的代码覆盖率来解决:基于源代码的覆盖率。您将需要安装 LLVM。
步骤如下:
"-C", "instrument-coverage",
"-C", "llvm-args=-runtime-counter-relocation",
添加环境变量以定位收集的覆盖率文件。
export LLVM_PROFILE_FILE="/tmp/server_%p%c.profraw"
测试结束后,结束服务器进程并收集
cov_dir
中生成的profraw文件和bin_dir
中的服务器二进制文件。使用grcov(cargo install grcov)生成html报告:
grcov ./cov_dir -b ./bin_dir --llvm-path ${LLVM_BIN_DIR} -s ${SRC} -t html