testthat3.3.1 package

Unit Testing for R

auto_test

Watches code and tests for changes, rerunning tests as appropriate.

capture_condition

Capture conditions, including messages, warnings, expectations, and er...

capture_output

Capture output to console

CheckReporter

Report results for R CMD check

compare_state

Compare two directory states.

compare

Provide human-readable comparison of two objects

comparison-expectations

Do you expect a value bigger or smaller than this?

context_start_file

Start test context from a file name

context

Describe the context of a set of tests.

DebugReporter

Interactively debug failing tests

default_reporter

Retrieve the default reporter

describe

describe: a BDD testing language

dir_state

Capture the state of a directory.

equality-expectations

Do you expect this value?

evaluate_promise

Evaluate a promise, capturing all types of output.

expect_all_equal

Do you expect every value in a vector to have this value?

expect_equivalent

Is an object equal to the expected value, ignoring attributes?

expect_error

Do you expect an error, warning, message, or other condition?

expect_invisible

Do you expect the result to be (in)visible?

expect_is

Do you expect to inherit from this class?

expect_known_output

Do you expect the results/output to equal a known value?

expect_length

Do you expect an object with this length or shape?

expect_less_than

Deprecated numeric comparison functions

expect_match

Do you expect a string to match this pattern?

expect_named

Do you expect a vector with (these) names?

expect_no_error

Do you expect the absence of errors, warnings, messages, or other cond...

expect_no_success

Test for absence of success or failure

expect_null

Do you expect NULL?

expect_output_file

Do you expect the output/result to equal a known good value?

expect_output

Do you expect printed output to match this pattern?

expect_reference

Do you expect a reference to this object?

expect_setequal

Do you expect a vector containing these values?

expect_silent

Do you expect code to execute silently?

expect_snapshot_file

Do you expect this code to create the same file as last time?

expect_snapshot_output

Snapshot helpers

expect_snapshot_value

Do you expect this code to return the same value as last time?

expect_snapshot

Do you expect this code to run the same way as last time?

expect_success

Test your custom expectations

expect_that

Expect that a condition holds.

expect_vector

Do you expect a vector with this size and/or prototype?

expect

The previous building block of all expect_ functions

expectation

Expectation conditions

extract_test

Extract a reprex from a failed expectation

fail

Declare that an expectation either passes or fails

FailReporter

Fail if any tests fail

find_reporter

Find reporter object given name or object.

find_test_scripts

Find test files

inheritance-expectations

Do you expect an S3/S4/R6/S7 object that inherits from this class?

is_informative_error

Is an error informative?

is_testing

Determine testing status

JunitReporter

Report results in jUnit XML format

ListReporter

Capture test results and metadata

local_edition

Temporarily change the active testthat edition

local_mocked_bindings

Temporarily redefine function definitions

local_mocked_r6_class

Mock an R6 class

local_mocked_s3_method

Mock S3 and S4 methods

local_snapshotter

Instantiate local snapshotting context

local_test_context

Temporarily set options for maximum reproducibility

local_test_directory

Locally set test directory options

LocationReporter

Test reporter: location

logical-expectations

Do you expect TRUE or FALSE?

make_expectation

Make an equality test.

MinimalReporter

Report minimal results as compactly as possible

mock_output_sequence

Mock a sequence of output from a function

MultiReporter

Run multiple reporters at the same time

not

Negate an expectation

oldskool

Old-style expectations.

ProgressReporter

Report progress interactively

quasi_label

Quasi-labelling

reexports

Objects exported from other packages

reporter-accessors

Get and set active reporter.

Reporter

Manage test reporting

RStudioReporter

Report results to RStudio

run_cpp_tests

Do C++ tests past?

set_max_fails

Set maximum number of test failures allowed before aborting the run

set_state_inspector

Check for global state changes

SilentReporter

Silently collect and all expectations

skip_on_travis

Superseded skip functions

skip

Skip a test for various reasons

SlowReporter

Find slow tests

snapshot_accept

Accept or reject modified snapshots

snapshot_download_gh

Download snapshots from GitHub

source_file

Source a file, directory of files, or various important subsets

StopReporter

Error if any test fails

succeed

Mark a test as successful

SummaryReporter

Report a summary of failures

takes_less_than

Does code take less than the expected amount of time to run?

TapReporter

Report results in TAP format

TeamcityReporter

Report results in Teamcity format

teardown_env

Run code after all test files

teardown

Run code before/after tests

test_dir

Run all tests in a directory

test_env

Generate default testing environment.

test_examples

Test package examples

test_file

Run tests in a single file

test_package

Run all tests in a package

test_path

Locate a file in the testing directory

test_that

Run a test

testthat_examples

Retrieve paths to built-in example test files

testthat_results

Create a testthat_results object from the test results as stored in ...

testthat_tolerance

Default numeric tolerance

testthat-package

An R package to make testing fun!

topic-name

Simulate a test environment

try_again

Evaluate an expectation multiple times until it succeeds

use_catch

Use Catch for C++ unit testing

verify_output

Verify output

watch

Watch a directory for changes (additions, deletions & modifications).

with_mock

Mock functions in a package.

Software testing is important, but, in part because it is frustrating and boring, many of us avoid it. 'testthat' is a testing framework for R that is easy to learn and use, and integrates with your existing 'workflow'.

  • Maintainer: Hadley Wickham
  • License: MIT + file LICENSE
  • Last published: 2025-11-25