Learn R Programming

tinytest (version 0.9.4)

run_test_dir: Run all tests in a directory

Description

run\_test\_dir runs all test files in a directory.

test_all is a convenience function for package development, that wraps run_test_dir. By default, it runs all files starting with test in ./inst/tinytest/. It is assumed that all functions to be tested are loaded.

Usage

run_test_dir(dir = "inst/tinytest", pattern = "^test.*\\.[rR]",
  at_home = TRUE, verbose = getOption("tt.verbose", TRUE),
  color = getOption("tt.pr.color", TRUE), remove_side_effects = TRUE,
  lc_collate = getOption("tt.collate", NA))

test_all(pkgdir = "./", testdir = "inst/tinytest", ...)

Arguments

dir

[character] path to directory

pattern

[character] A regular expression that is used to find scripts in dir containing tests (by default .R or .r files starting with test).

at_home

[logical] toggle local tests.

verbose

[logical] toggle verbosity during execution

color

[logical] toggle colorize output

remove_side_effects

[logical] toggle remove user-defined side effects. Environment variables (Sys.setenv()) and options (options()) defined in a test file are reset before running the next test file (see details).

lc_collate

[character] Locale setting used to sort the test files into the order of execution. The default NA ensures current locale is used. Set this e.g. to "C" to ensure bytewise and more platform-independent sorting (see details).

pkgdir

[character] scalar. Root directory of the package (i.e. direcory where DESCRIPTION and NAMESPACE reside).

testdir

[character] scalar. Subdirectory where test files are stored.

...

passed to run_test_dir.

Value

A tinytests object

Details

In general, we cannot guarantee that files will be run in any particular order accross all platforms, as it depends on the available collation charts (a chart that determines how alphabets are sorted). For this reason it is a good idea to create test files that run independent of each other so their order of execution does not matter. In tinytest, test files cannot share variables. The default behavior of test runners furher discourages interdependence by resetting environment variables and options that are set in a test file after the file is executed. If an environment variable needs to survive a single file, use base::Sys.setenv() explicitly. Similarly, if an option setting needs to survive, use base::options

See Also

Other test-files: build_install_test, run_test_file, summary.tinytests, test_package

Examples

Run this code
# NOT RUN {
# create a test file in tempdir
tests <- "
addOne <- function(x) x + 2

expect_true(addOne(0) > 0)
expect_equal(2, addOne(1))
"
testfile <- tempfile(pattern="test_", fileext=".R")
write(tests, testfile)

# extract testdir
testdir <- dirname(testfile)
# run all files starting with 'test' in testdir
out <- run_test_dir(testdir)
print(out)
dat <- as.data.frame(out)

# }

Run the code above in your browser using DataLab