在R中的testthat中使用Expect_error时,单元测试在天蓝色devops中失败

时间:2020-07-02 14:33:28

标签: r json azure-devops devops testthat

我正在运行单元测试以捕获函数中的错误。我的函数如下: 它必须从某个位置读取一个json文件。 我正在使用if条件来检查该位置是否有任何文件。 所以, 条件1:检查文件是否在该位置,然后继续其他步骤 条件2:如果该位置没有文件,则引发错误。 条件2如下:

test_that(desc = "Test for 'LoadData' Condition 2",
          code = {
            filePath = "./UnitTest/Data//Expected_Output2"
            expect_error(LoadData(inputPath = filePath),"There's no setting json file at location")
          }
)

在devops管道中运行时,它失败并显示以下日志消息:

/ |   0       | Condition 2   : stop if no json fileCondition 2   : stop if no json file: Start test: Test for 'LoadData' Condition 2
  ?#?:? [failure]
1End test: Test for 'LoadData' Condition 2

x |   0 1     | Condition 2   : stop if no json file

--------------------------------------------------------------------------------

???: failure: Test for 'LoadData' Condition 2

`LoadData(inputPath = filePath)` threw an error with unexpected message.

Expected match: "There's no setting json file at location"

Actual message: "There's no setting json file at ./UnitTest/Data//Expected_Output2"

Backtrace:

 1. testthat::expect_error(...)

 6. global::LoadData(inputPath = filePath)

我不知道为什么失败。请帮助我解决这个问题。

0 个答案:

没有答案