r - Declare function before each unit test with testthat package
问题描述
I want to create global functions which be used in each unit test of my package:
beforeTest()
which creates database table to testafterTest()
which drops the test database table.
Files:
/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...
# ...
# ...
})
The problem is that file unit_test_1.R
doesn't see the functions beforeTest()
and afterTest()
解决方案
推荐阅读
- html - 图像未调整的 HTML 链接
- sql-server - SQL Server:将 INSERT INTO SELECT 与具有相同源/目标数据库的 JOIN 一起使用时出现转换错误
- javascript - 为什么参数在函数中不可用
- reactjs - 在开发 React-Native 应用程序时,Chrome 开发者工具等效于什么?
- java - Android Studio 谷歌地图自定义地图,只想显示自定义地图但利用谷歌地图功能
- machine-learning - 为模拟任务创建机器学习模型
- python-3.x - 使用 Anaconda 在 MacOS 上安装 pdftotext 的问题
- docker - 在 Ubuntu 上 docker compose 时,Pycharm 中的连接被拒绝
- vba - 如何绕过使用 Application.SendKeys 破坏 InternetExplorer 对象
- javascript - 如何使用 vanilla JS 制作自定义动画增长饼图