gpt4 book ai didi

testing - 如何从覆盖率统计中排除生成的代码

转载 作者:IT王子 更新时间:2023-10-29 02:05:17 27 4
gpt4 key购买 nike

我的项目中有 thrift 生成的代码?我如何阻止这影响我的覆盖率统计数据?他们很沮丧。

最佳答案

go test 的这条帮助消息似乎建议您可以过滤正在测试的包:

-coverpkg pkg1,pkg2,pkg3
Apply coverage analysis in each test to the given list of packages.
The default is for each test to analyze only the package being tested.
Packages are specified as import paths.
Sets -cover.

另一个更简单的选择,也是我所做的,是将生成的代码导入为位于代码树之外的库包,因此覆盖工具在其统计信息中忽略它。

例如如果您的应用程序是 github.com/Fuser97381/myproj,请将生成的代码放在 github.com/Fuser97381/protocols 中。然后你的代码看起来像这样:

package main

import (
"github.com/Fuser97381/protocols/myproto"
"git.apache.org/thrift.git/lib/go/thrift"
)

...

关于testing - 如何从覆盖率统计中排除生成的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30742456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com