Learn R Programming

testit (version 0.11)

test_pkg: Run the tests of a package in its namespace

Description

The main purpose of this function is to expose the namespace of a package when running tests, which allows one to use non-exported objects in the package without having to resort to the triple colon ::: trick.

Usage

test_pkg(package, dir = c("testit", "tests/testit"))

Arguments

package

the package name

dir

the directory of the test files; by default, it is the directory testit/ or tests/testit/ under the current working directory

Value

NULL. All test files are executed, unless an error occurs.

Details

The tests are assumed to be under the testit/ or tests/testit/ directory by default (depending on your working directory is the package root directory or the tests/ directory). This function also looks for the tests/testit/ directory under the package installation directory when the user-provided dir does not exist. The test scripts must be named of the form test-*.R; other R scripts will not be treated as test files (but may also be useful, e.g. you can source() them in tests).

For R CMD check, this means the test R scripts (test-*.R are under pkg_root/tests/testit/. The R scripts are executed with sys.source in the namespace of the package to be tested; when an R script is executed, the working directory is the same as the directory containing this script, and all existing objects in the test environment will be removed before the code is executed.

See Also

The testthat package (much more sophisticated).

Examples

Run this code
# NOT RUN {
test_pkg("testit")
# }

Run the code above in your browser using DataLab