Go Coverage Report Integration with Jenkins



我想知道是否有任何工具可以将go test -coverprofile=cover.out转换为 Jenkins 可以接受的格式? 我找到了一些工具,如go-junit-report和go2xunit,但它们实际上只是从go test -v转换输出,这不是覆盖率报告。

我想直接了解 Jenkins 中的详细测试覆盖率。 基本上,我想在 Jenkins 网页中看到 go tool cover -func=cover.outgo tool cover -html=cover.out 的输出。

有几种 go 工具可以将覆盖数据从 go test 转换为 Jenkins 的 Cobertura:gocover-cobertura,或带有 gocov-xml 的 gocov。

您可以按如下方式使用gocover-cobertura

$ go get github.com/t-yuki/gocover-cobertura
$ go test -coverprofile=cover.out example.com/demo/...
ok      example.com/demo    0.008s  coverage: 0.0% of statements
ok      example.com/demo/cmd/demo   0.020s  coverage: 23.4% of statements
$ gocover-cobertura < cover.out > coverage.xml
$ head coverage.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage line-rate="0.35415787" branch-rate="0" version="" timestamp="1520609235359" lines-covered="839" lines-valid="2369" branches-covered="0" branches-valid="0" complexity="0">
        <sources>
                <source>/usr/local/go/src</source>
                <source>/Users/wilfred/workspace/go-scratch/src</source>
        </sources>
        <packages>
                <package name="example.com/demo/cmd/demo" line-rate="0.4848485" branch-rate="0" complexity="0">
                        <classes>

请注意,您需要 Go 1.10+ 才能在一次运行中针对多个包运行-coverprofile

https://github.com/AlekSi/gocov-xml

这就是我们需要的。 使用Coberuta插件生成覆盖范围配置文件。

没有用于 Go 覆盖率报告的专用插件,也没有用于通用代码覆盖率的插件。

对于这样的报告,我使用 HTML 发布器插件发布在构建期间创建.html文件。

最新更新