File: test_file.Rd

package info (click to toggle)
r-cran-testthat 3.1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,224 kB
  • sloc: cpp: 9,261; ansic: 37; sh: 15; makefile: 5
file content (69 lines) | stat: -rw-r--r-- 2,441 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/test-files.R
\name{test_file}
\alias{test_file}
\title{Run all tests in a single file}
\usage{
test_file(path, reporter = default_compact_reporter(), package = NULL, ...)
}
\arguments{
\item{path}{Path to file.}

\item{reporter}{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()}).

See \link{Reporter} for more details and a list of built-in reporters.}

\item{package}{If these tests belong to a package, the name of the package.}

\item{...}{Additional parameters passed on to \code{test_dir()}}
}
\value{
A list (invisibly) containing data about the test results.
}
\description{
Helper, setup, and teardown files located in the same directory as the
test will also be run.
}
\section{Special files}{

Certain \code{.R} files have special significance in testthat:
\itemize{
\item Test files start with \code{test} and are executed in alphabetical order.
\item Setup files start with \code{setup} 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())}. See \code{vignette("test-fixtures")}
for more details.
\item Helper files start with \code{helper} and are executed before tests are
run and, unlike setup files, are also loaded by \code{devtools::load_all()}.
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 \verb{R/}, just like any other internal function.
}

There is another type of special file that we no longer recommend using:
\itemize{
\item Teardown files start with \code{teardown} and are executed after the tests
are run. Now we recommend interleaving setup and cleanup code in \verb{setup-}
files, making it easier to check that you automatically clean up every
mess that you make.
}

All other files are ignored by testthat.
}

\section{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.
}

\examples{
path <- testthat_example("success")
test_file(path)
test_file(path, reporter = "minimal")
}