run_test_dir {tinytest} | R Documentation |
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.
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", ...)
dir |
|
pattern |
|
at_home |
|
verbose |
|
color |
|
remove_side_effects |
|
lc_collate |
|
pkgdir |
|
testdir |
|
... |
passed to |
A tinytests
object
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
Other test-files: build_install_test
,
run_test_file
,
summary.tinytests
,
test_package
# 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)