testthis

CRAN status

Overview

Testhis provides RStudio addins for common package development tasks:

It furhter provides functions for managing subdirectories of the tests/testthat directory of a package:

Testthis also provides the experimental feature get_test_coverage(). In contrast to the popular covr package, this does not calculate the coverage automatically. It rather requires you to put special comment tags in your test-source files. You can use it like a todo/checklist.

Installation

# Testthis is on CRAN:
install.packages("testthis")

# You can also install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("s-fleck/testthis")

Usage

library(testthis)

open_testfile()  # can be assigned to a hotkey
## The file `tests/testthat/test_README.Rmd` does not exist. 
## You can create it with testthis::test_skeleton().

test_skeleton()
## * Creating `tests/testthat/test_myscript.R`

open_testfile()
## > Opens `tests/testthat/test_myscript.R` (in RStudio)

test_this()  # can be assigned to a hotkey
## > Runs tests in `tests/testthat/test_myscript.R` (in RStudio,)
## > works from the original .R file as well as from the file containing the tests

For a detailed overview of all testthis features with usage examples please refer to the package vignette.