Cross-package code coverage in golang


(Kwk) #1

I've read the article https://www.elastic.co/blog/code-coverage-for-your-golang-system-tests and wondered, if you have managed to get cross-package coverage?

To explain what I mean: Suppose you have a package A and you have tests for this package that exist in the same folder. Let's say these tests cover 50% of the code which is pretty low.
On the other hand, say you have package B that includes some packages (including A). The tests for package B most likely will cover some pieces of package A that are not yet covered by the package's own tests.

So far we only managed to get coverage information for package A and B but not the combination of the two. Do you know what I mean?

I'd be happy to hear you thoughts on this. Maybe you even think it's not a good idea to have cross-package coverage.

Thank you in advance for your response.


(ruflin) #2

In case I understand your question correctly, I think we are already doing this. It requires that during the build time of the test binary, you have to list all go packages for which you want to create the report first. See here in our Makefile: https://github.com/elastic/beats/blob/master/libbeat/scripts/Makefile#L77

Second you must use a tool like gotestcover (see https://github.com/elastic/beats/blob/master/libbeat/scripts/Makefile#L127) to get the coverage reports for multiple packages.

And last, the different coverage reports must be collected and put into on coverage report: https://github.com/elastic/beats/blob/master/libbeat/scripts/Makefile#L154

Does this help?


(system) #3

This topic was automatically closed after 21 days. New replies are no longer allowed.