Test user interaction with file.choose()

51 views Asked by At

I have a function that contains file.choose() that I would like to be covered by tests using testthat (and in a minor extent using goodpractices).

I know such interactive function is not universally loved. I don't adore it myself but in a package I wrote, I really need such helpers for beginner users (with the hope of bringing them to non-interactive alternative).

Is test a way to do it automatically, eg without picking a file manually?

I know such a question has (partly) already been asked and I understand the idea behind the answer but I have the feeling that it circumvents my problem rather than solving it. Perhaps, it is, by essence, impossible to tackle.

Below is a code that could help. We would expect no message in the end.

library(testthat)

fc <- function(x){
  x <- file.choose()
  return(x)
}

test_that("interactive function works",{
  expect_true(is.character(fc()))
})
0

There are 0 answers