Question

Is it possible to control the order in which test_package executes testing scripts? I would like to start by executing some code that creates some objects shared by all individual tests. Therefore, this script needs to be executed first, before the actual test-blabla.R scripts.

I could try something like test-AAA.R or test-000.R, but I am not sure if the dir function used by testthat to list the scripts in a package, returns the same (alphabetical?) order of files on all platforms.

Was it helpful?

Solution

?test_dir says

Test files start with ‘test’ and are executed in alphabetical order (but they shouldn't have dependencies). Helper files start with ‘helper’ and loaded before any tests are run.

So, use helper files. i.e. create a file with a name that begins with "helper" and put in it the code that you need to run before running all the tests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top