Skip to content

fail function for forcing a test failure #47

Description

@richierocks

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

http://stackoverflow.com/questions/12507229/how-to-make-a-test-fail-with-the-testthat-package

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)
{
expect_that(
NULL,
function(message)
{
expectation(FALSE, message)
},
info = info,
NULL
)
}

Usage is, for example,

test_that("failure test", fail())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions