run_test_dir {tinytest} | R Documentation |
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", 2),
color = getOption("tt.pr.color", TRUE),
remove_side_effects = TRUE,
cluster = NULL,
lc_collate = getOption("tt.collate", NA),
...
)
test_all(pkgdir = "./", testdir = "inst/tinytest", ...)
Arguments
dir |
|
pattern |
|
at_home |
|
verbose |
|
color |
|
remove_side_effects |
|
cluster |
A |
lc_collate |
|
... |
Arguments passed to |
pkgdir |
|
testdir |
|
Value
A tinytests
object
Details
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 further 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()
Parallel tests
If inherits(cluster, "cluster")
the tests are paralellized over a
cluster of worker nodes. tinytest will be loaded onto each cluster
node. All other preparation, including loading code from the tested package,
must be done by the user. It is also up to the user to clean up the cluster
after running tests. See the 'using tinytest' vignette for examples:
vignette("using_tinytest")
.
See Also
makeCluster
,
clusterEvalQ
, clusterExport
Other test-files:
build_install_test()
,
exit_file()
,
run_test_file()
,
summary.tinytests()
,
test_package()
Examples
# 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)