The tests are executed in a clean environment with the namespace of the
package to be tested as the parent environment, which means you can use
non-exported objects in the package without having to resort to the triple
colon ::: trick.
test_pkg(package = pkg_name(), dir = c("testit", "tests/testit"), update = NA)NULL. All test files are executed, unless an error occurs.
The package name. By default, it is detected from the
DESCRIPTION file if exists.
The directory of the test files; by default, it is the directory
testit/ or tests/testit/ under the current working directory,
whichever exists. You can also specify a custom directory.
If TRUE, update snapshot files with actual output
instead of comparing. If NA (the default), update snapshot files
only if they are tracked by GIT (so you can view the diffs in GIT and
decide whether to accept or discard the changes). If FALSE, never
update snapshot files and always compare. For NA and FALSE,
if the snapshot test fails, it will throw an error with a message showing
the location of the failed test. For TRUE, it will update the
snapshot file and never throw an error.
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). The test scripts must be named of
the form test-*.R (or test-*.md for snapshot tests); other
files will not be treated as test files (but may also be useful, e.g. you can
source() other scripts in tests).
When a test is executed, the working directory is the same as the directory containing this test, and all existing objects in the test environment will be removed before the code is executed.
See https://pkg.yihui.org/testit/#snapshot-testing for more details about snapshot testing.
if (FALSE) {
test_pkg("testit")
}
Run the code above in your browser using DataLab