test_package_pure: Run all tests in a package purely

View source: R/pure-package.R

test_package_pureR Documentation

Run all tests in a package purely

Description

These pure functions will only run test_that() calls.

  • test_local_pure() tests a local source package.

  • test_package_pure() tests an installed package.

  • test_check_pure() checks a package during R CMD check.

Tests live in tests/testthat.

Usage

test_package_pure(package, reporter = check_reporter(), ...)

test_check_pure(package, reporter = check_reporter(), ...)

test_local_pure(path = ".", reporter = NULL, ...)

Arguments

package

If these tests belong to a package, the name of the package.

reporter

Reporter to use to summarise output. Can be supplied as a string (e.g. "summary") or as an R6 object (e.g. SummaryReporter$new()).

See Reporter for more details and a list of built-in reporters.

...

Additional arguments passed to testthat::test_dir()

path

Path to directory containing tests.

Value

A list (invisibly) containing data about the test results.

Special files

There are two types of .R file that have special behaviour:

  • Test files start with test and are executed in alphabetical order.

  • Setup files start with setup and are executed before tests. If clean up is needed after all tests have been run, you can use withr::defer(clean_up(), teardown_env()). See vignette("test-fixtures") for more details.

There are two other types of special file that we no longer recommend using:

  • Helper files start with helper and are executed before tests are run. They're also loaded by devtools::load_all(), so there's no real point to them and you should just put your helper code in R/.

  • Teardown files start with teardown and are executed after the tests are run. Now we recommend interleave setup and cleanup code in setup- files, making it easier to check that you automatically clean up every mess that you make.

All other files are ignored by testthat.

Environments

Each test is run in a clean environment to keep tests as isolated as possible. For package tests, that environment that inherits from the package's namespace environment, so that tests can access internal functions and objects.


EmilHvitfeldt/monkeytest documentation built on May 12, 2022, 12:34 a.m.