EVOLUTION-MANAGER
Edit File: test_package.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Run all tests in a package</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for test_package {testthat}"><tr><td>test_package {testthat}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Run all tests in a package</h2> <h3>Description</h3> <ul> <li> <p><code>test_local()</code> tests a local source package. </p> </li> <li> <p><code>test_package()</code> tests an installed package. </p> </li> <li> <p><code>test_check()</code> checks a package during <code style="white-space: pre;">R CMD check</code>. </p> </li></ul> <p>Tests live in <code>tests/testthat</code>. </p> <h3>Usage</h3> <pre> test_package(package, reporter = check_reporter(), ...) test_check(package, reporter = check_reporter(), ...) test_local(path = ".", reporter = NULL, ..., load_package = "source") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>package</code></td> <td> <p>If these tests belong to a package, the name of the package.</p> </td></tr> <tr valign="top"><td><code>reporter</code></td> <td> <p>Reporter to use to summarise output. Can be supplied as a string (e.g. "summary") or as an R6 object (e.g. <code>SummaryReporter$new()</code>). </p> <p>See <a href="Reporter.html">Reporter</a> for more details and a list of built-in reporters.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments passed to <code><a href="test_dir.html">test_dir()</a></code></p> </td></tr> <tr valign="top"><td><code>path</code></td> <td> <p>Path to directory containing tests.</p> </td></tr> <tr valign="top"><td><code>load_package</code></td> <td> <p>Strategy to use for load package code: </p> <ul> <li><p> "none", the default, doesn't load the package. </p> </li> <li><p> "installed", uses <code><a href="../../base/html/library.html">library()</a></code> to load an installed package. </p> </li> <li><p> "source", uses <code><a href="../../pkgload/html/load_all.html">pkgload::load_all()</a></code> to a source package. To configure the arguments passed to <code>load_all()</code>, add this field in your DESCRIPTION file: </p> <div class="sourceCode"><pre>Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE) </pre></div> </li></ul> </td></tr> </table> <h3>Value</h3> <p>A list (invisibly) containing data about the test results. </p> <h3><code style="white-space: pre;">R CMD check</code></h3> <p>To run testthat automatically from <code style="white-space: pre;">R CMD check</code>, make sure you have a <code>tests/testthat.R</code> that contains: </p> <div class="sourceCode"><pre>library(testthat) library(yourpackage) test_check("yourpackage") </pre></div> <h3>Special files</h3> <p>Certain <code>.R</code> files have special significance in testthat: </p> <ul> <li><p> Test files start with <code>test</code> and are executed in alphabetical order. </p> </li> <li><p> Setup files start with <code>setup</code> and are executed before tests. If clean up is needed after all tests have been run, you can use <code>withr::defer(clean_up(), teardown_env())</code>. See <code>vignette("test-fixtures")</code> for more details. </p> </li> <li><p> Helper files start with <code>helper</code> and are executed before tests are run and, unlike setup files, are also loaded by <code>devtools::load_all()</code>. Helper files can be necessary for side-effect-y code that you need to run when developing the package interactively. It's certainly possible to define custom test utilities in a helper file, but they can usually be defined below <code style="white-space: pre;">R/</code>, just like any other internal function. </p> </li></ul> <p>There is another type of special file that we no longer recommend using: </p> <ul> <li><p> Teardown files start with <code>teardown</code> and are executed after the tests are run. Now we recommend interleaving setup and cleanup code in <code style="white-space: pre;">setup-</code> files, making it easier to check that you automatically clean up every mess that you make. </p> </li></ul> <p>All other files are ignored by testthat. </p> <h3>Environments</h3> <p>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. </p> <hr /><div style="text-align: center;">[Package <em>testthat</em> version 3.1.5 <a href="00Index.html">Index</a>]</div> </body></html>