Check code coverage

Testing
R

This workflow measures code coverage for unit tests and reports the code coverage as a percentage of the total number of lines covered by unit tests vs. the total number of lines in the codebase.

Author

Pharmaverse

Published

August 1, 2023

About the gh-action

Example of use: falcon R package

Why should I use this?

This workflow measures code coverage for unit tests and reports the code coverage as a percentage of the total number of lines covered by unit tests vs. the total number of lines in the codebase in an R package.

It’s important to note that code coverage is only telling you if a test exists, not that the test is testing all that should be tested against that line of code.

For information on how to add testing to R packages, R-pkgs.org covers setting up tests with testthat.

How do I set it up?

You can call this action via adding a call to this job in a GitHub Actions workflow. A minimal example that runs this on commits to master is:

name: Code coverage
# sourced from phuse-org/devops-toolkit

on:
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
      - ready_for_review
    branches:
      - main
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  coverage:
    name: Code Coverage
    uses: phuse-org/devops-toolkit/.github/workflows/test-coverage.yml@main

The deets

The covr R package is used to calculate the coverage.