Expectations

Objects

expect_equal() expect_identical()

Does code return the expected value?

expect_null()

Does code return NULL?

expect_type() expect_s3_class() expect_s7_class() expect_s4_class()

Does code return an object inheriting from the expected base type, S3 class, or S4 class?

Vectors

expect_length()

Does code return a vector with the specified length?

expect_lt() expect_lte() expect_gt() expect_gte()

Does code return a number greater/less than the expected value?

expect_match() expect_no_match()

Does a string match a regular expression?

expect_named()

Does code return a vector with (given) names?

expect_setequal() expect_mapequal() expect_contains() expect_in()

Does code return a vector containing the expected values?

expect_true() expect_false()

Does code return TRUE or FALSE?

expect_vector()

Does code return a vector with the expected size and/or prototype?

Side-effects

expect_error() expect_warning() expect_message() expect_condition()

Does code throw an error, warning, message, or other condition?

expect_no_error() expect_no_warning() expect_no_message() expect_no_condition()

Does code run without error, warning, message, or other condition?

expect_invisible() expect_visible()

Does code return a visible or invisible object?

expect_output()

Does code print output to the console?

expect_silent()

Does code execute silently?

local_test_context() local_reproducible_output()

Locally set options for maximal test reproducibility

Snapshot testing

expect_snapshot()

Snapshot testing

expect_snapshot_value()

Snapshot testing for values

expect_snapshot_file() announce_snapshot_file() compare_file_binary() compare_file_text()

Snapshot testing for whole files

snapshot_accept() snapshot_review()

Snapshot management

Test helpers

local_edition() edition_get()

Temporarily change the active testthat edition

is_testing() is_parallel() is_checking() is_snapshot() testing_package()

Determine testing status

skip() skip_if_not() skip_if() skip_if_not_installed() skip_if_offline() skip_on_cran() skip_on_os() skip_on_ci() skip_on_covr() skip_on_bioc() skip_if_translated()

Skip a test

teardown_env()

Run code after all test files

set_state_inspector()

State inspected

Run tests

auto_test()

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

auto_test_package()

Watches a package for changes, rerunning tests as appropriate.

describe() it()

describe: a BDD testing language

test_dir()

Run all tests in a directory

test_file()

Run tests in a single file

test_package() test_check() test_local()

Run all tests in a package

test_path()

Locate a file in the testing directory

test_that()

Run a test

use_catch()

Use Catch for C++ Unit Testing

Reporters

Reporter

Manage test reporting

CheckReporter

Check reporter: 13 line summary of problems

DebugReporter

Test reporter: start recovery.

FailReporter

Test reporter: fail at end.

JunitReporter

Test reporter: summary of errors in jUnit XML format.

ListReporter

List reporter: gather all test results along with elapsed time and file information.

LocationReporter

Test reporter: location

MinimalReporter

Test reporter: minimal.

MultiReporter

Multi reporter: combine several reporters in one.

ProgressReporter CompactProgressReporter ParallelProgressReporter

Test reporter: interactive progress bar of errors.

RStudioReporter

Test reporter: RStudio

SilentReporter

Test reporter: gather all errors silently.

StopReporter

Test reporter: stop on error

SummaryReporter

Test reporter: summary of errors.

TapReporter

Test reporter: TAP format.

TeamcityReporter

Test reporter: Teamcity format.

Mocking

local_mocked_bindings() with_mocked_bindings()

Mocking tools

Expectation internals

expect()

The building block of all expect_ functions

expectation() new_expectation() exp_signal() is.expectation()

Construct an expectation object

fail() succeed()

Default expectations that always succeed or fail.

expect_success() expect_no_success() expect_failure() expect_snapshot_failure() expect_no_failure() show_failure()

Tools for testing expectations