我想创建在程序包的每个单元测试中使用的全局函数:
beforeTest()
创建数据库表进行测试afterTest()
会删除测试数据库表。文件:
/tests/testthat.R:
library(mypackage)
library(testthat)
beforeTest <- function() {
# implementation
}
afterTest <- function() {
# implementation
}
test_check("mypackage")
/tests/testthat/unit_test_1.R:
test_that("mytest", {
beforeTest()
on.exit(afterTest())
# implemetation of the unit test...
# ...
# ...
})
问题在于文件unit_test_1.R
看不到函数beforeTest()
和afterTest()