Rstudio IDE not recognising tests

Hi all,

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

Can you show the actual package? Or if not, then create a public toy package that reproduces this?

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.

Actually just removing the testthat:: call before testthat::test_that() would do the trick. Duh.

I am fairly sure that that's not the problem, though. If I

  1. clone your repo
  2. start RStudio with the project file
  3. install testthat (it is not included in your renv lock file)
  4. install the package (Build -> Install and restart)
  5. run the tests: (Build -> Test package)

then I get

The `code` argument to `test_that()` must be a braced expression to get 
accurate file-line information for failures.

IDK if this was your original problem, but to fix it modify your test file to use a braced expression:

testthat::test_that("I am a test!", {
  expect_equal(hello(), "Hello, world!")
})

And then the test runs fine with Build -> Test package.