gotestyourself / gotestsum

'go test' runner with output optimized for humans, JUnit XML for CI integration, and a summary of the test results.
Apache License 2.0
1.99k stars 118 forks source link

generate coverage reports #335

Open bstpierre opened 1 year ago

bstpierre commented 1 year ago

@dnephin commented in @302 in a discussion about coverage output:

go tool cover (https://pkg.go.dev/cmd/cover) is a similar idea. It can produce 2 reports: coverage percentage per function, and a detailed HTML report. The HTML report effectively has this information, but it's not presented this way.

It seems like it wouldn't be too difficult to copy and modify https://cs.opensource.google/go/go/+/refs/tags/go1.20.3:src/cmd/cover/html.go to make a new report in the format you want. It is possible there is a tool out there that has already done the work, I haven't looked. If you want to build it, it could work as gotestsum tool cover-report or something similar. A new issue for this would be great.

I use coverage reporting in CI, and GitLab's coverage visualization requires cobertura format. I'm currently using gocover-cobertura to generate this report. It would be handy to be able to generate both the junit and cobertura reports from gotestsum all at once -- possibly alongside the html output that was mentioned in the comment that dnephin was replying to.

mitar commented 1 year ago

I am in the same boat. I am also using Gitlab. Not sure if there is really an issue with additional step of conversion to cobertura format though?

My main issue is that Gitlab supports only one number for coverage, but currently gotestsum returns one number per tested module (see #340).

mitar commented 3 months ago

I think I am realizing that the coverage for the main package (the . by this tool) is the total coverage? Also it might be useful to run coverage with -coverpkg ./... if you have many integration tests across sub-packages.