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.
Usage
test_pkg(package = pkg_name(), dir = c("testit", "tests/testit"), update = NA)Arguments
- package
The package name. By default, it is detected from the
DESCRIPTIONfile if exists.- dir
The directory of the test files; by default, it is the directory
testit/ortests/testit/under the current working directory, whichever exists. You can also specify a custom directory.- update
If
TRUE, update snapshot files with actual output instead of comparing. IfNA(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). IfFALSE, never update snapshot files and always compare. ForNAandFALSE, if the snapshot test fails, it will throw an error with a message showing the location of the failed test. ForTRUE, it will update the snapshot file and never throw an error.
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). 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.