Parameterized Unit Testing

This is an extension of the 'testthat' package that lets you add parameters to your unit tests. Parameterized unit tests are often easier to read and more reliable, since they follow the DNRY (do not repeat yourself) rule.

This package is an extension to testthat that enables parameterized unit testing in R.


patrick is currently only available on GitHub. Install it using devtools.


To use patrick as a testing tool within your package, add it to your list of Suggests and Remotes within your package's DESCRIPTION.



Many packages within R employ the following pattern when writing tests:

test_that("Data is a successfully converted: numeric", {
  input <- convert(numeric_data)
  expect_is(input, "numeric")

test_that("Data is a successfully converted: character", {
  input <- convert(character_data)
  expect_is(input, "character")

While explicit, recycling a test pattern like this is prone to user error and other issues, as it is a violation of the classic DNRY rule (do not repeat yourself). patrick eliminates this problem by creating test parameters.

with_parameters_test_that("Data is successfully converted:", {
    input <- convert(test_data)
    expect_is(input, type)
  test_name = c("numeric", "character"),
  test_data = list(numeric_data, character_data),
  type = c("numeric", "character")

Parameterized tests behave exactly the same as standard testthat tests. Per usual, you call all of your tests with devtools::test, and they'll also run during package checks. Each executes independently and then your test report will produce a single report. A complete name for each test will be formed using the initial test description and the strings in the test_name parameter.

Small sets of cases can be reasonably passed a parameters to with_parameters_test_that. This becomes less readable when the number of cases increases. To help mitigate this issue, patrick provides a case generator helper function.

with_parameters_test_that("Data is successfully converted:", {
    input <- convert(test_data)
    expect_is(input, type)
    numeric = list(test_data = numeric_data, type = "numeric"),
    character = list(test_data = character_data, type = "character")


This package is inspired by parameterized testing packages in other languages, notably the parameterized library in Python.


Please read the for details on how to contribute to this project.


This is not an officially supported Google product.


Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.1.0 by Michael Quinn, 2 months ago

Report a bug at

Browse source code at

Authors: Michael Quinn [aut, cre]

Documentation:   PDF Manual  

Apache License 2.0 license

Imports dplyr, purrr, rlang, testthat, tibble

Suggested by DoubleML, eflm, mombf, spectralGraphTopology.

See at CRAN