test_that

0th

Percentile

Create a test.

A test encapsulates a series of expectations about small, self-contained set of functionality. Each test is contained in a context and contains multiple expectations.

Usage
test_that(desc, code)
Arguments
desc

test name. Names should be kept as brief as possible, as they are often used as line prefixes.

code

test code containing expectations

Details

Tests are evaluated in their own environments, and should not affect global state.

When run from the command line, tests return NULL if all expectations are met, otherwise it raises an error.

Aliases
  • test_that
Examples
# NOT RUN {
test_that("trigonometric functions match identities", {
  expect_equal(sin(pi / 4), 1 / sqrt(2))
  expect_equal(cos(pi / 4), 1 / sqrt(2))
  expect_equal(tan(pi / 4), 1)
})
# Failing test:
# }
# NOT RUN {
test_that("trigonometric functions match identities", {
  expect_equal(sin(pi / 4), 1)
})
# }
Documentation reproduced from package testthat, version 2.0.1, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.