GitHub - r-lib/testthat: An R 📦 to make testing 😀 (original) (raw)

testthat

CRAN status R-CMD-check Codecov test coverage

Overview

Testing your code can be painful and tedious, but it greatly increases the quality of your code. testthat tries to make testing as fun as possible, so that you get a visceral satisfaction from writing tests. Testing should be addictive, so you do it all the time. To make that happen, testthat:

testthat draws inspiration from the xUnit family of testing packages, as well as from many of the innovative ruby testing libraries, likerspec, testy,bacon andcucumber.

testthat is the most popular unit testing package for R and is used by thousands of CRAN packages.

If you’re not familiar with testthat, the testing chapter in R packages gives a good overview, along with workflow advice and concrete examples.

Installation

Install the released version from CRAN

install.packages("testthat")

Or the development version from GitHub:

install.packages("pak")

pak::pak("r-lib/testthat")

Usage

The easiest way to get started is withusethis. Assuming you’re in a package directory, just run usethis::use_test("name") to create a test file, and set up all the other infrastructure you need. If you’re using RStudio, press Cmd/Ctrl + Shift + T (or run devtools::test() if not) to run all the tests in a package.