expect_error

  • You just need to create an error.
expect_error(stop("Bye"))
  • You can confirm if the error matches
f <- function() {
  stop("Calculation failed [location 1]")
}

expect_error(f(),  "Calculation failed")
  • We also have the functions:
    • expect_warning()
    • expect_message()