时间:2015-05-04 17:56:05

标签: r testing testthat

是否可以在test_that()或expect_XXX()调用中写入否定条件?具体来说,我想测试一个不包含子字符串的字符串,如下所示:

expect_that("Apples, Oranges, Banana", !matches('Onion'))

expect_not_match("Apples, Oranges, Banana", 'Onion')

我知道我可以将expect_true()与例如: grep的:

expect_true(length(grep("Onion", "Apples, Oranges, Banana")) == 0)

但这看起来并不太可读。

1 个答案:

答案 0 :(得分:4)

testthat::not怎么样?

expect_that("Apples, Oranges, Banana", not(matches('Onion')))​​​​​​