【问题标题】:Catch the error in testthat but dont stop the loop - testing在 testthat 中捕获错误但不要停止循环 - 测试
【发布时间】:2021-01-08 12:44:34
【问题描述】:

我最近编写了一个包,我想测试几个函数,当输入正确时,这些函数会提供一个 data.frame,如果不正确,它会将输入作为文件传递到错误文件夹并登录到日志中。日志文件。

现在的问题是:我如何报告这个动作并测试函数是否将文件移动到 test_that 的错误文件夹中?

谢谢!

【问题讨论】:

    标签: r unit-testing testing package testthat


    【解决方案1】:

    用错误的输入调用你的函数,然后检查错误文件是否按你的意愿创建?

    test_that("Error file is created", {
      yourfunction(x)
      expect_true(file.exists("errorfile.error")
    })
    

    yourfunction() 之前,您还必须创建错误的输入 x。

    【讨论】:

    • 嗯...好主意!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    相关资源
    最近更新 更多