covtracer

Tools for contextualizing tests, built using covr test traces.

https://github.com/genentech/covtracer

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (19.8%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Tools for contextualizing tests, built using covr test traces.

Basic Info
Statistics
  • Stars: 23
  • Watchers: 5
  • Forks: 4
  • Open Issues: 7
  • Releases: 1
Created almost 5 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---




```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

options(
  tibble.print_min = 5,
  tibble.print_max = 5,
  width = 120L
)

suppressPackageStartupMessages(library(dplyr))
```

# covtracer 


[![CRAN](https://img.shields.io/cran/v/covtracer.svg)](https://cran.r-project.org/package=covtracer) 
[![R-CMD-check](https://github.com/genentech/covtracer/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/genentech/covtracer/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/genentech/covtracer/graph/badge.svg)](https://app.codecov.io/gh/genentech/covtracer)


Tools for contextualizing tests, built using `covr` test traces. This 
package provides utilities for linking an assortment of test and 
package information to paint a more complete picture of how a test
was performed.

```mermaid
flowchart LR
    tests[Tests] <--> traces[Traced Exprs] <--> code[Package Code] <--> docs[Package Documentation]
```

## Installation

To install, use `remotes` to install directly from
[GitHub](https://github.com/Genentech/covtracer)

Functionality hinges heavily on coverage objects prepared using `covr` 
(≥ 3.5.1.9003). To ensure suggested dependency requirements are met, 
install with `dependencies = TRUE` (satisfy all dependencies).

```{r, eval = FALSE}
# will install covr >= v3.5.1.9003 for examples
remotes::install_github("Genentech/covtracer", dependencies = TRUE)
```

## Motivation

Tests are not black boxes. When it comes to verifying behaviors of code, we can
use observations about the code that is executed by a test to build a more
complete picture of exactly what the test does. This is a core part of software
validation. By combining information about each test, the tested package code
and linking that code to package documentation, we can link documented behaviors
to their respective tests.

## Getting Started

Test traces are connected to evaluated code using `covr` (≥ 3.5.1.9003).
Likewise, a new option flag (`covr.record_tests`) must be set in order to record
tests alongside the coverage traces. Finally, the package to evaluate must be
installed with source references in order to map all the components together. 

That's a lot to configure, but if you're in a position where this test data is
valuable hopefully it's worth the setup. 

```{r, results = "hide", message = FALSE, warning = FALSE}
library(covtracer)

# additional demo packages
library(dplyr)
library(withr)
library(covr)

withr::with_temp_libpaths({
  pkg <- system.file("examplepkg", package = "covtracer")

  install.packages(
    pkg,
    type = "source",
    repos = NULL,
    quiet = TRUE,
    INSTALL_opts = c("--with-keep.source", "--install-tests")
  )

  options(covr.record_tests = TRUE)
  cov <- covr::package_coverage(pkg)

  ttdf <- test_trace_df(cov)
})
```

There's a lot of info in the resulting `data.frame`, but we'll focus on just the
critical piece, showing which tests evaluate code related to which documented
behaviors. Below we show how one might map unit tests to evaluated, documented
objects.

> **Note:** Below we ignore documentation for datasets and S4 class
> constructors. Although these are defined in the package, they don't map to
> testable lines of code because they are constructed when the package is built.

```{r}
traceability_matrix <- ttdf %>%
  filter(!doctype %in% c("data", "class")) %>% # ignore objects without testable code
  select(test_name, file) %>%
  filter(!duplicated(.)) %>%
  arrange(file)

traceability_matrix
```

We can quickly see which functions or methods are entirely untested.

## Use Cases

The `data.frame` returned by `test_trace_df` contains a ton of information, and
we can measure a few dimensions of the quality of tests with some relatively
straightforward analysis.

### Traceability Matrix

Perhaps the most immediate use case is to map unit tests to documented
behaviors. 

```{r}
ttdf %>%
  filter(!doctype %in% c("data", "class")) %>% # ignore objects without testable code
  select(test_name, file) %>%
  filter(!duplicated(.)) %>%
  arrange(file)
```

### Finding Untested Behaviors

Once we can map unit testing to documentation, we can filter down to only
documentation that is not covered by any test.

```{r}
ttdf %>%
  filter(!doctype %in% c("data", "class")) %>% # ignore objects without testable code
  select(test_name, count, alias, file) %>%
  filter(is.na(count)) %>%
  arrange(alias)
```

### Filter For Only Directly Tested Behaviors

Some tests evaluate a broad set of functionality by calling functions that
themselves call out to internal package functions. This is often perfectly fine,
since the mechanisms of calling those internal functions are limited by the
surfaced user-facing functions. Nevertheless, whether a function is called
directly is a good indication of the "unit"-ness of a unit test. You may
consider only the coverage of directly tested functions.

```{r}
ttdf %>%
  filter(!doctype %in% c("data", "class")) %>% # ignore objects without testable code
  select(direct, alias) %>%
  group_by(alias) %>%
  summarize(any_direct_tests = any(direct, na.rm = TRUE)) %>%
  arrange(alias)
```

Owner

  • Name: Genentech
  • Login: Genentech
  • Kind: organization
  • Location: South San Francisco, CA

GitHub Events

Total
  • Issues event: 4
  • Watch event: 1
  • Delete event: 1
  • Issue comment event: 4
  • Push event: 3
  • Pull request review event: 1
  • Pull request event: 2
  • Create event: 1
Last Year
  • Issues event: 4
  • Watch event: 1
  • Delete event: 1
  • Issue comment event: 4
  • Push event: 3
  • Pull request review event: 1
  • Pull request event: 2
  • Create event: 1

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 41
  • Total pull requests: 39
  • Average time to close issues: 3 months
  • Average time to close pull requests: 8 days
  • Total issue authors: 2
  • Total pull request authors: 4
  • Average comments per issue: 0.59
  • Average comments per pull request: 1.18
  • Merged pull requests: 38
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: about 22 hours
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • dgkf (31)
  • maksymiuks (8)
Pull Request Authors
  • dgkf (36)
  • maksymiuks (2)
  • cicdguy (1)
  • armcn (1)
Top Labels
Issue Labels
bug (5) case (1)
Pull Request Labels
enhancement (1)

Packages

  • Total packages: 1
  • Total downloads:
    • cran 527 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
cran.r-project.org: covtracer

Contextualizing Tests

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 527 Last month
Rankings
Dependent packages count: 28.6%
Dependent repos count: 35.2%
Average: 50.2%
Downloads: 86.7%
Maintainers (1)
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.2.0 depends
  • stats * imports
  • tools * imports
  • R6 * suggests
  • cli * suggests
  • covr >= 3.5.1.9003 suggests
  • dplyr * suggests
  • igraph * suggests
  • knitr * suggests
  • remotes * suggests
  • rmarkdown * suggests
  • testthat * suggests
  • withr * suggests
inst/examplepkg/DESCRIPTION cran
  • R6 * imports
  • methods * imports
  • testthat >= 3.0.0 suggests
tests/testthat/packages/no.evaluable.code/DESCRIPTION cran
  • testthat * suggests
tests/testthat/packages/reexport.srcref/DESCRIPTION cran
  • testthat >= 3.0.0 suggests
.github/workflows/check-full.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/check-r-package v1 composite
  • r-lib/actions/setup-pandoc v1 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v1 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions/checkout v3 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v3 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
tests/testthat/packages/list.obj/DESCRIPTION cran
  • testthat * suggests