OK, since no one has answered and I did some more research I will try to offer an answer for others myself. Please, other readers, give feedback.
- Yes, you are.
- Yes,
shinytest would be the best way. In particular, I enjoy the way shinytest is used in this article, where the author uses it as part of test_that calls.
However, that article does not describe how to test it as a module and inside a package. Let's start with the latter.
Package
I guess for the purpose of this question the difference between being part of a package and not mostly relates to where you place files and how you execute them. If not part of a package, you just follow the article above and execute your test script using testthat::test_dir() or testthat::test_file(), as described here.
If part of a package, I generally place my tests in tests/testthat and execute them using devtools::test().
Module
To test a module using shinytest, I put it inside a minimal test app. The test app is only for testing purposes, so I put it inside tests/testthat. Then I instantiate my minimal test app in the test using the following code and start testing
app <- shinytest::ShinyDriver$new("minimal_test_app.R", loadTimeout = 1e+05)
expect_equal(app$getValue("whatever"), "this_is_the_correct_value")
The next problem is that the app needs to find the code containing the module. If not inside a package, you can just use source and library inside minimal_test_app.R to get the module and the required external libraries. If inside a package, I place the command pkg_load::load_all() as the first row of minimal_test_app.R. I guess the setup is a bit similar to what is described under " Application objects created by functions" here.
Comparison to using testthat::test_server
I find that the tests run quite a bit slower when using shinytest than when using testthat::testServer, perhaps because we are using a headless browser. Therefore, I would use testthat::testServer when possible. However, in cases such as the one above, where events trigger server calculations that in turn update the UI, shinytest is the only option that I am aware of.
Test fixtures
Creating a test app such as this one is a type of test fixture, and should be cleaned up after the test.