I'm working on a package (this one) where I set up my tests according to the testthat workflow. This includes having my tests in ./testthat/testthat/
folder and a ./testthat/testthat.R
file as follows:
library(testthat)
library(rpostgisLT)
test_check("rpostgisLT")
All the tests require that the testthat
package is attached (thus I didn't use the testthat::function
referencing.
Just after restarting R (without testthat
attached) I try to run devtools::document()
but it breaks, because it doesn't find the testthat
functions that I use in the tests. Of course, after attaching testthat
devtools::document()
runs through.
Why does devtools::document()
look into the /tests
folder? Shouldn't it only document functions in the /R
folder?
devtools::document()
is a wrapper for roxygen2::roxygenize
. If you read the documentation of the latter it says:
Note that roxygen2 is a dynamic documentation system: it works using by inspecting loaded objects in the package. This means that you must be able to load the package in order to document it.
And also there is an argument load_code
which says:
A function used to load all the R code in the package directory. It is called with the path to the package, and it should return an environment containing all the sourced code.
Therefore, it looks like it is reading all .R
files. However, I have a feeling that it skips all .R files that start with test_
in the name (otherwise I would have seen my packages break as well). I think the problem is your helper_db.R
file where you use testthat
functions in a file not starting with test_
.