Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

expect_that

Expect that a condition holds.


Description

[Superseded]

An old style of testing that's no longer encouraged.

Usage

expect_that(object, condition, info = NULL, label = NULL)

Arguments

object

Object to test.

Supports limited unquoting to make it easier to generate readable failures within a function or for loop. See quasi_label for more details.

condition,

a function that returns whether or not the condition is met, and if not, an error message to display.

info

Extra information to be included in the message. This argument is soft-deprecated and should not be used in new code. Instead see alternatives in quasi_label.

label

Used to customise failure messages. For expert use only.

Value

the (internal) expectation result as an invisible list

3rd edition

[Deprecated]

This style of testing is formally deprecated as of the 3rd edition. Use a more specific expect_ function instead.

See Also

fail() for an expectation that always fails.

Examples

expect_that(5 * 2, equals(10))
expect_that(sqrt(2) ^ 2, equals(2))
## Not run: 
expect_that(sqrt(2) ^ 2, is_identical_to(2))

## End(Not run)

testthat

Unit Testing for R

v3.0.2
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], RStudio [cph, fnd], R Core team [ctb] (Implementation of utils::recover())
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.