我正在为我的包裹编写测试,我想使用宏观经济数据,而不是人为地随机分配。问题是,当我使用read.csv('my_file.csv')
然后运行test_that
时,所有使用我的数据的测试都将被忽略。例如
library('tseries')
library('testthat')
data<-read.csv('my_file.csv')
test_that('ADF test',{
vec<-data[,2]
expect_is(adf.test(vec),'htest')
})
运行“ testpackage”后,我未获得有关测试失败或通过的信息。问题出在哪里?
答案 0 :(得分:0)
testthat
仅在测试未成功的情况下在控制台中返回错误:
library(testthat)
data<-iris
test_that('test1',{
expect_is(data$Petal.Length,'numeric')
})
test_that('test2',{
expect_is(data$Species,'numeric')
})
#> Error: Test failed: 'test2'
#> * <text>:8: data$Species inherits from `factor` not `numeric`.
由reprex package(v0.3.0)于2020-09-21创建
您可以使用test_file
或test_dir
来获得结果:
res <- test_file('mytest.R',
reporter = "list",
env = test_env(),
start_end_reporter = TRUE,
load_helpers = TRUE,
wrap = TRUE)
√ | OK F W S | Context
x | 1 1 | mytest
--------------------------------------------------------------------------------
mytest.R:8: failure: test2
data$Species inherits from `factor` not `numeric`.
--------------------------------------------------------------------------------
== Results =====================================================================
OK: 1
Failed: 1
Warnings: 0
Skipped: 0
Warning message:
`encoding` is deprecated; all files now assumed to be UTF-8