0

前提条件が満たされていない場合(ファイルの欠落など)、失敗させたいテストがあります。

明確にするために、これが私がやりたい例です:

test_that("...", {
    if ( ... precondition to execute the test is not met... ) {
        expect_true(FALSE) # Make it fail without going further
    }

    expect_that( ... real test here ...)
})

今私の質問は次のとおりです:testthatパッケージに何かfail()のような期待がありますか、それとも私はいつも書く必要がありますか?expect_true(FALSE)

4

2 に答える 2

4

fail現在、機能はありませんtestthat。私はあなたがのようなものが欲しいと思います

fail <- function(message = "Failure has been forced.", info = NULL, label = NULL)
{
  expect_that(
    NULL,
    function(message)
    {
      expectation(FALSE, message) 
    },
    info,
    label
  )
}

使用法は、例えば、

test_that("!!!", fail())
于 2012-09-20T15:53:18.867 に答える
0

失敗は選択肢ではありません...

使用してみてくださいstop

test_that("testingsomething", {
  if(file.exists("foo.txt")){
      stop("foo.txt already exists")
   }
  foo = writeFreshVersion("foo.txt")
  expect_true(file.exists("foo.txt"))
}
)
于 2012-09-20T07:04:34.837 に答える