Unit testing for R
open sourceMITfree
testthat is the most widely used unit testing framework for R packages. Tests are written with test_that() blocks and expect_*() expectations (equality, errors, warnings, output and more), and snapshot tests record printed output, errors or images and flag any change. It runs from the R console, from devtools::test() or during R CMD check, reports results as it goes, and supports mocking, test fixtures and parallel runs. It's maintained by Hadley Wickham and Posit as part of the r-lib collection.
Problems it solves
- write unit tests for my R package
- check that my R function throws the right error
- snapshot test printed output and plots in R
- run my R package's tests during R CMD check
Features
- test_that blocks with expect_* expectations
- snapshot tests for output, errors and images
- mocking and test fixtures
- parallel test runs
- runs under devtools::test() and R CMD check
