有幾種工具可用於將覆蓋率數據從go test
轉換爲Jenkins的Cobertura:gocover-cobertura或gocov和gocov-xml。
您可以使用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>
請注意,您需要轉到1.10+到run -coverprofile
against multiple packages in one run。
我剛剛發現https://github.com/AlekSi/gocov-xml,我認爲它會做我們需要的! –
啊,很好。很高興知道! –