Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
fail function for forcing a test failure #47
There's been a request for a
I had a go at writing one, for possible inclusion in the package.
' Makes a testfail
' The fail function forces a test to fail.
' @param message a string to display.
' @param infoextra information to be included in the message (useful when writing tests in loops).
fail <- function(message = "Failure has been forced.", info = NULL)
Usage is, for example,
Since the utility of this function isn't very clear, here's a possible use case. It isn't life-changing, but I think it qualifies as a minor perk.
When you want to test a new function, it can be quite useful to write down all the tests that you can think of in one go. Rather than worrying about how each test needs to be implemented, you just want a placeholder that fails, in order to let you know that you haven't written that test yet. After you've decided upon each test, you can go back and replace the fails with real tests.
You could just stick a