I am writing a R package, and I\'m using testthat for unit testing. Many of my unit tests are for testing functions that work on a certain object specific to my package. For the
I understand that files in tests/testthat/
that begin with helper
are sourced before running any tests by testthat. So you can place helper functions for tests inside suitably named helper-*.R
within tests/testthat/
.
From R help for source_file
from testthat
(?testthat::source_file
)
The expectation is that the files can be sourced in alphabetical
order. Helper scripts are R scripts accompanying test scripts but
prefixed by ‘helper’. These scripts are once before the tests are
run.
An example can be seen in the source code for dplyr on github
.
As for testdata. I follow the advice from one comment from this question: Where to put data for automated tests with testthat? and use inst/testdata
, then access the files with system.file("testdata",...,package="my_package")