Skip to contents

The goal of modsquad is to demonstrate how to test the modules in a Shiny app-package using testthat, shiny::testServer(), and shinytest2.

modsquad combines two earlier app-packages: mstsap (testServer() tests) and msst2ap (shinytest2 tests).

All examples come from the Modules chapter of Mastering Shiny.

Installation

You can install modsquad from GitHub using the code below:

remotes::install_github("mjfrigaard/modsquad",
  force = TRUE, quiet = TRUE
)
library(modsquad)
#> Loading required package: shiny

Set up

There are specific instructions for setting up shinytest2 in the shinytest2-setup.Rmd vignette.

Utility function/testServer() tests

Tests for the utility functions are in tests/testthat/test-find_vars.R and the unit-tests.Rmd vignette. Tests for the module server functions and standalone app functions are in tests/testthat/ and the testserver-tests.Rmd vignette.

shinytest2 tests

The output from devtools::test() is below:

==> devtools::test()

ℹ Testing modsquad
✔ | F W  S  OK | Context
✔ |          1 | shinytest2-datasetApp [4.8s]                                                   
⠼ |          5 | shinytest2-gghistApp       
⠋ |         11 | shinytest2-gghistApp                                   
⠙ |         12 | shinytest2-gghistApp                       
✔ |         13 | shinytest2-gghistApp [5.1s]                                
✔ |          5 | shinytest2-histogramApp [3.6s]                                                 
✔ |          2 | shinytest2-selectVarApp [2.2s]                                                 
✔ |          1 | shinytest2 [4.2s]                                                              

══ Results ══════════════════════════════════════════════════════════════════
Duration: 19.9 s

[ FAIL 0 | WARN 0 | SKIP 0 | PASS 22 ]

🔥 Your tests are lit 🔥

Known issue

The following warning is given when running shinytest2 tests in an app package:

Warning message:
In shiny::loadSupport(app_dir, renv = renv, globalrenv = globalrenv) :
  Loading R/ subdirectory for Shiny application, but this directory appears to 
contain an R package. Sourcing files in R/ may cause unexpected behavior.

Don’t worry–there is an open issue on GitHub for this!