New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail function for forcing a test failure #47

richierocks opened this Issue Sep 20, 2012 · 2 comments


None yet
2 participants

richierocks commented Sep 20, 2012

There's been a request for a fail function in testthat, that just makes a test fail.

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)
expectation(FALSE, message)
info = info,

Usage is, for example,

test_that("failure test", fail())

This comment has been minimized.

richierocks commented Sep 21, 2012

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.


This comment has been minimized.

spacedman commented Sep 23, 2012

You could just stick a stop("Not done this yet") in your test - that will show as an error rather than a failure in the test runner. Semantically I find the idea of a failure being conjured from thin air quite disturbing, whereas saying 'stop!' seems more natural. HMMV.

@hadley hadley closed this in eb8aff3 Mar 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment