test_dir: Run all tests in a directory

Description Usage Arguments Value Special files Environments

View source: R/test-files.R

Description

This function is the low-level workhorse that powers test_local() and test_package(). Generally, you should not call this function directly. In particular, you are responsible for ensuring that the functions to test are available in the test env (e.g. via load_package).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
test_dir(
  path,
  filter = NULL,
  reporter = NULL,
  env = NULL,
  ...,
  load_helpers = TRUE,
  stop_on_failure = TRUE,
  stop_on_warning = FALSE,
  wrap = lifecycle::deprecated(),
  package = NULL,
  load_package = c("none", "installed", "source")
)

Arguments

path

Path to directory containing tests.

filter

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".

reporter

Reporter to use to summarise output. Can be supplied as a string (e.g. "summary") or as an R6 object (e.g. SummaryReporter$new()).

See Reporter for more details and a list of built-in reporters.

env

Environment in which to execute the tests. Expert use only.

...

Additional arguments passed to grepl() to control filtering.

load_helpers

Source helper files before running the tests? See source_test_helpers() for more details.

stop_on_failure

If TRUE, throw an error if any tests fail.

stop_on_warning

If TRUE, throw an error if any tests generate warnings.

wrap

DEPRECATED

package

If these tests belong to a package, the name of the package.

load_package

Strategy to use for load package code:

  • "none", the default, doesn't load the package.

  • "installed", uses library() to load an installed package.

  • "source", uses pkgload::load_all() to a source package.

Value

A list (invisibly) containing data about the test results.

Special files

There are two types of .R file that have special behaviour:

There are two other types of special file that we no longer recommend using:

All other files are ignored by testthat.

Environments

Each test is run in a clean environment to keep tests as isolated as possible. For package tests, that environment that inherits from the package's namespace environment, so that tests can access internal functions and objects.


testthat documentation built on Oct. 4, 2021, 9:07 a.m.