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()