How to Get Code Coverage Reports Without Sharing Code with Codecov.io

[This article was first published on jakub::sobolewski, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In R the most popular way to get the code coverage report is to use codecov.io with usethis::use_coverage.

It reports the coverage in a nice badge you can attach to the README.

But you can also get a coverage report with a cobertura-action:

  1. Create a step in CI to calculate the coverage with {covr} and convert it to the cobertura xml format with covr::to_cobertura.
  2. Add 5monkeys/cobertura-action@master step that reads the produced xml file and adjust other parameters as needed.
- name: Test coverage
  run: |
    renv::install(c("covr", "xml2"))
    cov <- covr::package_coverage(
      quiet = FALSE,
      clean = FALSE,
      install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
    )
    covr::to_cobertura(cov, filename = "covr.xml")
  shell: Rscript {0}

- uses: 5monkeys/cobertura-action@master
  with:
    path: ./covr.xml
    minimum_coverage: 75
    only_changed_files: true

The action will post a comment in a PR with coverage result after a successful run.

Coverage

The downside of using this action instead of codecov.io is that it shows only a summary of coverage, while with codecov.io you can see the coverage of each file. But if you don’t want to share your private code with this external service, this is a good alternative.

You can always create a more detailed report locally or export it as an artifact from CI.

I highly recommend setting up coverage report in your project, one way or the other, especially when dealing with legacy code. This way you can continuously get feedback how well you’re doing in your testing efforts.

But remember, however many tests you have, they don’t prove your system is good.

Find the coverage that makes you feel comfortable.

To leave a comment for the author, please follow the link and comment on their blog: jakub::sobolewski.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)