Learn R Programming

testthat (version 0.2)

test_that: Create a test.

Description

Create a test.

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

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

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 returns

Examples

Run this code
test_that("trigonometric functions match identies", {
expect_that(sin(pi / 4), equals(1 / sqrt(2)))
expect_that(cos(pi / 4), equals(1 / sqrt(2)))
expect_that(tan(pi / 4), equals(1))
})
# Failing test:
test_that("trigonometric functions match identies", {
expect_that(sin(pi / 4), equals(1))
})

Run the code above in your browser using DataLab