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

fail

Default expectations that always succeed or fail.


Description

These allow you to manually trigger success or failure. Failure is particularly useful to a pre-condition or mark a test as not yet implemented.

Usage

fail(
  message = "Failure has been forced",
  info = NULL,
  trace_env = caller_env()
)

succeed(message = "Success has been forced", info = NULL)

Arguments

message

a string to display.

info

Character vector continuing additional information. Included for backward compatibility only and new expectations should not use it.

trace_env

If is.null(trace), this is used to automatically generate a traceback running from test_code()/test_file() to trace_env. You'll generally only need to set this if you're wrapping an expectation inside another function.

Examples

## Not run: 
test_that("this test fails", fail())
test_that("this test succeeds", succeed())

## 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.