tinytest (version 1.2.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", 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

[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).

cluster

A makeCluster object.

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

...

Arguments passed to run_test_file

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.

Value

A tinytests object

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

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()

See Also

makeCluster, clusterEvalQ, clusterExport

Other test-files: build_install_test(), exit_file(), 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 DataCamp Workspace