Description Usage Arguments Details Examples

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.

1 | ```
test_that(desc, code)
``` |

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

`code` |
test code containing expectations |

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.

1 2 3 4 5 6 7 8 9 10 11 12 | ```
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)
})
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.