test: Execute testthat tests in a package

View source: R/test.R

testR Documentation

Execute testthat tests in a package


  • test() runs all tests in a package. It's a shortcut for testthat::test_dir()

  • test_active_file() runs test() on the active file.

  • test_coverage() computes test coverage for your package. It's a shortcut for covr::package_coverage() plus covr::report().

  • test_coverage_active_file() computes test coverage for the active file. It's a shortcut for covr::file_coverage() plus covr::report().


test(pkg = ".", filter = NULL, stop_on_failure = FALSE, export_all = TRUE, ...)

test_active_file(file = find_active_file(), ...)

test_coverage(pkg = ".", show_report = interactive(), ...)

  file = find_active_file(),
  filter = TRUE,
  show_report = interactive(),
  export_all = TRUE,



The package to use, can be a file path to the package or a package object. See as.package() for more information.


If not NULL, only tests with file names matching this regular expression will be executed. Matching is performed on the file name after it's stripped of "test-" and ".R".


If TRUE, throw an error if any tests fail.


If TRUE (the default), export all objects. If FALSE, export only the objects that are listed as exports in the NAMESPACE file.


additional arguments passed to wrapped functions.


One or more source or test files. If a source file the corresponding test file will be run. The default is to use the active file in RStudio (if available).


Show the test coverage report.

devtools documentation built on Oct. 12, 2022, 1:06 a.m.