Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cobertura XML test coverage output #87

Closed
fdcds opened this issue Feb 10, 2020 · 5 comments
Closed

Cobertura XML test coverage output #87

fdcds opened this issue Feb 10, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@fdcds
Copy link

fdcds commented Feb 10, 2020

We already use gotestsum for JUnit XML output and would also like to output our line-by-line test coverage in Cobertura XML format, because that is what our test analysis system understands.

Currently we have to use 2 additional tools for that (i.e. three tools in total):

Is it possible to integrate the functionality of these tools into gotestsum, so we need less tools and have a one stop shop for test analysis?

@dnephin dnephin added the enhancement New feature or request label Feb 10, 2020
@dnephin
Copy link
Member

dnephin commented Feb 12, 2020

Thank you for opening this issue!

I was not familiar with gocov or the Cobertura so I had a look. As I understand it, the situation is something like this:

  • As of go1.10 a lot of what gocov does is unnecessary. go test now supports adding a -coverprofile when running with multiple package
  • gocov-xml is close to what you want, except that instead of reading the golang coverage format it reads the gocov JSON

Since the input to the xml is a file created by go test, there is little benefit for that program to be part of gotestsum. It could be a completely separate tool as none of the code would overlap. The only benefit to integrating it in this repo would ease maintenance and installation for users of both tools.

I found https://github.com/t-yuki/gocover-cobertura which seems to be exactly what would be needed. It appears to read the standard go coverage files and output the Cobertura XML format. If I understand correctly the go tool cover command has been included in the standard release since go1.2, so that at least reduces the number of tools to 2.

I'm hesitant to integrate that tool since the code wouldn't benefit from that integration.

@fdcds
Copy link
Author

fdcds commented Feb 13, 2020

* [As of go1.10](https://golang.org/doc/go1.10#test) a lot of what `gocov` does is unnecessary. `go test` now supports adding a `-coverprofile` when running with multiple package

Maybe I am missing something, but Go 1.10 (go test -coverprofile=...) does not make gocov obsolete but actually makes it possible. A small part of gocov is a tiny wrapper around go test -coverprofile=... and the larger part of gocov deals with converting that to this JSON format and some other part converts it into textual form.

Since the input to the xml is a file created by go test, there is little benefit for that program to be part of gotestsum. It could be a completely separate tool as none of the code would overlap. The only benefit to integrating it in this repo would ease maintenance and installation for users of both tools.

ACK

I found https://github.com/t-yuki/gocover-cobertura which seems to be exactly what would be needed. It appears to read the standard go coverage files and output the Cobertura XML format. If I understand correctly the go tool cover command has been included in the standard release since go1.2, so that at least reduces the number of tools to 2.

Thanks for having a look! I must have somehow missed this tool when searching for ways to get the coverage reports into our test analysis.

I'm hesitant to integrate that tool since the code wouldn't benefit from that integration.

ACK

@fdcds fdcds closed this as completed Feb 13, 2020
@dnephin
Copy link
Member

dnephin commented Feb 13, 2020

Maybe I am missing something, but Go 1.10 (go test -coverprofile=...) does not make gocov obsolete but actually makes it possible.

It is definitely possible I am wrong. I should elaborate on how I reached this conclusion:

  • Go1.10 was first released on 2018-02-16. gocov dates back to June 2012.

  • Previous to go 1.10 it was not possible to run go test with multiple package if the --coverprofile flag was used. It required that you run every pacakge with a separate go test command. From the go1.10 release notes:

    Also, the go test -coverprofile option is now supported when running multiple tests.

  • Because of this limitation many people used tools like gocov, or bash scripts to run each package separately.

gocov does also provide some help with the reports, however as of Go1.2 (first rleased on 2013-12-01) the go toolchain provides similar functionality: https://golang.org/doc/go1.2#cover.

There may be other features of gocov that I'm missing, but at least the primary features seem to be covered by the go toolchain. The interchange format doesn't seem all that valuable itself if no other tools support it.

I guess maybe the reports it produces may be a better than what the standard go tool cover provide?

@fdcds
Copy link
Author

fdcds commented Feb 14, 2020

Thanks for writing down the history. I only looked at the current page and am not that familiar with the history of the Go ecosystem. From your write up it seems indeed that gocov is a dead-end. Thanks again for the hint regarding gocover-cobertura.

@arvenil
Copy link

arvenil commented Sep 2, 2020

Hi, @dnephin wrote best summary ever, after dealing with those issues for several years I can confirm there is really nothing much to add. To me gocov is obsolete since we can do now go test -coverprofile=coverage.out -covermode=atomic -coverpkg=./... ./....

Now the only missing thing is test output and coverage output conversion to different formats. This library seems to deal with tests and I'm using https://github.com/t-yuki/gocover-cobertura for coverage. But honestly, for simplification, I really would love to use just one, well maintained, tool. Especially that gocover-cobertura doesn't seem to work really well, there are issues with paths for example. If you guys have ever time or desire to properly handle coverage as well then it would be really amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants