R: Run a test

test_that {testthat} | R Documentation

## Run a test

### Description

A test encapsulates a series of expectations about a small, self-contained set of functionality. Each test lives in a file and contains multiple expectations, like `expect_equal()` or `expect_error()`.

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

### Usage

    test_that(desc, code)

### Arguments

`desc` | Test name. Names should be brief, but evocative. They are only used by humans, so do you
`code` | Test code containing expectations. Braces (`{}`) should always be used in order to get accurate location data for test failures.

### Value

When run interactively, returns `invisible(TRUE)` if all tests pass, otherwise throws an error.

### Examples

    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)
    })

    ## Not run:
    test_that("trigonometric functions match identities", {
      expect_equal(sin(pi / 4), 1)
    })

    ## End(Not run)

[Package testthat version 3.1.0 Index]