# Cross-package code coverage in golang

**URL:** <https://discuss.elastic.co/t/cross-package-code-coverage-in-golang/62627>\
**Category:** Beats\
**Created:** [October 10, 2016, 10:50am UTC](https://discuss.elastic.co/t/cross-package-code-coverage-in-golang/62627 "2016-10-10T10:50:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwk/32/12385_2.png) [@kwk](https://discuss.elastic.co/u/kwk)\
**Post date:** [October 10, 2016, 10:50am UTC](https://discuss.elastic.co/t/cross-package-code-coverage-in-golang/62627/1 "2016-10-10T10:50:41Z")

</div>

I've read the article [https://www.elastic.co/blog/code-coverage-for-your-golang-system-tests](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.

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [October 10, 2016, 11:04am UTC](https://discuss.elastic.co/t/cross-package-code-coverage-in-golang/62627/2 "2016-10-10T11:04:23Z")

</div>

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](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](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](https://github.com/elastic/beats/blob/master/libbeat/scripts/Makefile#L154)

Does this help?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 31, 2016, 10:51am UTC](https://discuss.elastic.co/t/cross-package-code-coverage-in-golang/62627/3 "2016-10-31T10:51:12Z")

</div>

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