Question

I have written a series of test_that tests. There is one test_that test which has a side-effect of creating a sqlite3 table. The rest of the tests rely on this sqlite3 table. Is there a way to force this one test to run before any of the other tests do?

Was it helpful?

Solution

If you are using test_dir or test_package (otherwise you can just put the tests in the same file after the sqlite test), you can put your test that generates the table in its own file and use naming conventions for execution. For example, inside tests/run.R you could have:

test_file("tests/testthat/myspecialfile.R")   
test_dir("tests/testthat/")   # will run every file with a name starting with `test`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top