tinytest (version 1.2.4)

test_package: Test a package during R CMD check or after installation

Description

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 the DESCRIPTION file.

testdir

[character] scalar. Path to installed directory. By default tinytest assumes that test files are in inst/tinytest/, which means that after installation and thus during R CMD check they are in tinytest/. 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 makeCluster object.

...

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

setup_tinytest

Other test-files: build_install_test(), exit_file(), run_test_dir(), run_test_file(), summary.tinytests()

Examples

Run this code
# NOT RUN {
# 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")
# }

Run the code above in your browser using DataCamp Workspace