Run all tests in an installed package. Throw an error and print all failed test
results when one or more tests fail if not in interactive mode (e.g. when
R CMD check tests a package). This function is intended to be
used by R CMD check or by a user that installed a package that
uses the tinytest test infrastructure.
Usage
test_package(
pkgname,
testdir = "tinytest",
lib.loc = NULL,
at_home = FALSE,
ncpu = NULL,
...
)Arguments
- pkgname
[character]scalar. Name of the package, as in theDESCRIPTIONfile.- testdir
[character]scalar. Path to installed directory. By default tinytest assumes that test files are ininst/tinytest/, which means that after installation and thus duringR CMD checkthey are intinytest/. See details for using alternate paths.- lib.loc
[character]scalar. location where the package is installed.- at_home
[logical]scalar. Are we at home? (see Details)- ncpu
A positive integer, or a
makeClusterobject.- ...
extra arguments passed to
run_test_dir(e.g.ncpu).
Value
If interactive(), a tinytests object. If not
interactive(), an error is thrown when at least one test fails.
Details
We set at_home=FALSE by default so R CMD check will run the
same as at CRAN. See the package vignette (Section 4) for tips on how to set
up the package structure.
vignette("using_tinytest",package="tinytest").
Package authors who want to avoid installing tests with the package can
create a directory under tests. If the test directoy is called
"tests/foo", use test_package("pkgname", testdir="foo") in
tests/tinytest.R.
See also
Other test-files:
build_install_test(),
exit_file(),
run_test_dir(),
run_test_file(),
summary.tinytests()
Examples
if (FALSE) { # \dontrun{
# Create a file with the following content, to use
# tinytest as your unit testing framework:
if (requireNamespace("tinytest", quietly=TRUE))
tinytest::test_package("your package name")
} # }