I have a question I have been unable to find the answer. I have a number of testthat tests in a package, stored on the tests/testthat folder, using format test_<yada>.R Some of the test names match R scripts files in the R/ folder, some do not. However the IDE does not recognise these as tests, and the button for "Run Tests" is not available. When running the tests the package also does not seem to load.
I cannot for the life of me find out what's wrong.
Are the build tools configured to build a package?
yes
Is testthat installed?
yes
Using renv for this project, is renv synced?
yes
Have you tried to change the tests name from test_ to test-?
yes
Which version of RStudio are you using?
2021.09.1 Build 372
I'm sure there's something embarrasingly stupid that I have overlooked but I cannot find it. Has anyone ever come across with this issue? My google results are clouded by basic configurations and common issues with testthat, but this is not one of those.
I'd appreciate a hint.
Full Rstudio version:
RStudio 2021.09.1+372 "Ghost Orchid" Release (8b9ced188245155642d024aa3630363df611088a, 2021-11-08) for macOS
Mozilla/5.0 (Macintosh; Intel Mac OS X 11_6_0) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.10 Chrome/69.0.3497.128 Safari/537.36
Here I have a minimum example that shows the issue (on my machine):
The issue I think arises if the tests were created manually, and not using the usethis package. I usually use that package, but this time using renv I did not add it. It seems that usethis::use_test() is doing something else beside creating the test.
Even changing the name from test_hello.R to test-hello.R does not get the IDE the prompt that the script is a test. One needs to run usethis::use_test() and "rewrite" the test to work.
I thought the "Run tests" feature was a standard feature of the IDE when using testthat inside a package, but it may be a feature actually brought by usethis. Curious.