R `testthat`test在会话中运行时确实运行,但会导致测试出错

R `testthat`test在会话中运行时确实运行,但会导致测试出错,r,testthat,R,Testthat,我对下面的test有问题。特别是第一次测试 它在我直接执行它时运行(整个test\u-that()块),但在该文件上使用testthat::test\u-file()时失败(显然,当所有测试都执行时)。从 如果我正确读取错误,则错误发生在expect\u known\u value()函数中,而不是在validate()函数中,因为该函数工作正常(如果我把它放在x之后,它现在使用的是相同的代码。我认为,validate.CORRECT.rda文件已损坏,因为我无法将其读入Rstudio。因此我删

我对下面的
test有问题。特别是第一次测试

它在我直接执行它时运行(整个
test\u-that()
块),但在该文件上使用
testthat::test\u-file()
时失败(显然,当所有测试都执行时)。从


如果我正确读取错误,则错误发生在
expect\u known\u value()
函数中,而不是在
validate()
函数中,因为该函数工作正常(如果我把它放在
x之后,它现在使用的是相同的代码。我认为,
validate.CORRECT.rda
文件已损坏,因为我无法将其读入Rstudio。因此我删除了它,它起了作用。由于这是一个无法重现的问题,类似于打字错误,我认为它可能应该被删除。您愿意这样做吗?
context("validate()")

x <- emeScheme_raw
print(validate( x = x, errorIfStructFalse = TRUE))

test_that(
  "validata_raw() returns correct value when correct",
  {
    expect_known_value(
      object = validate( x = x, errorIfStructFalse = TRUE),
      file = "validate.CORRECT.rda"
    )
  }
)

names(x)[1] <- "experiment"

test_that(
  "validata_raw() fails",
  {
    expect_known_value(
      object =  validate( x = x, errorIfStructFalse = FALSE),
      file = "validate.DIFFERENCES.rda"
    )
  }
)

test_that(
  "validata_raw() fails",
  {
    expect_error(
      object = validate( x = x, errorIfStructFalse = TRUE),
      regexp = ("Structure of the object to be evaluated is wrong. See the info above for details.")
    )
  }
)
 testthat::test_file("./tests/testthat/test-validate.R")
✔ | OK F W S | Context
⠙ |  1 1     | validate()Names: 1 string mismatch
✖ |  2 1     | validate() [0.8 s]
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
test-validate.R:10: error: validata_raw() returns correct value when correct
missing value where TRUE/FALSE needed
1: expect_known_value(object = validate(x = x, errorIfStructFalse = TRUE), file = "validate.CORRECT.rda") at ./tests/testthat/test-validate.R:10
2: compare(act$val, ref_val, ...)
3: compare.default(act$val, ref_val, ...)
4: all.equal(x, y, ...)
5: all.equal.list(x, y, ...)
6: all.equal(target[[i]], current[[i]], check.attributes = check.attributes, use.names = use.names, ...)
7: all.equal.list(target[[i]], current[[i]], check.attributes = check.attributes, use.names = use.names, ...)
8: all.equal(target[[i]], current[[i]], check.attributes = check.attributes, use.names = use.names, ...)
9: all.equal.list(target[[i]], current[[i]], check.attributes = check.attributes, use.names = use.names, ...)
10: all.equal(target[[i]], current[[i]], check.attributes = check.attributes, use.names = use.names, ...)
11: all.equal.default(target[[i]], current[[i]], check.attributes = check.attributes, use.names = use.names, ...)
12: all.equal.list(target, current, ...)
13: paste0("Component ", if (use.names && nt[i] == nc[i]) dQuote(nt[i]) else i, ": ", mi)
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

══ Results ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Duration: 0.8 s

OK:       2
Failed:   1
Warnings: 0
Skipped:  0