Tests

Expand the callout boxes below to review what we’ve covered in the last five chapters:

In the Documentation chapter we covered:

  1. An introduction to the roxygen2 (5.1 roxygen2 intro) package, and

  2. Some tips for documenting app-package functions (5.2 Documenting app functions)

The applications in Chapter 5 (Documentation) can be accessed with the launch() or get() functions from the shinypak R package:

# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)

Chapter 1 applications:

list_apps(regex = '^05')
## # A tibble: 1 × 2
##   branch      last_updated       
##   <chr>       <dttm>             
## 1 05_roxygen2 2024-07-30 09:25:19

In Dependencies, we walked through:

  1. How to give users of our app-package access to it’s functions (i.e., exports (6.1 Exports)), and

  2. What to do with the functions we use from other packages in the R/ folder (i.e., imports (6.2 Imports))

The applications in Chapter 6 (Dependencies) can be accessed with the launch() or get() functions from the shinypak R package:

# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)

Chapter 6 applications:

list_apps(regex = '^06')
## # A tibble: 2 × 2
##   branch           last_updated       
##   <chr>            <dttm>             
## 1 06.1_pkg-exports 2024-07-31 05:04:44
## 2 06.2_pkg-imports 2024-07-31 05:07:47

Data covered the three common locations for data in R packages:

  1. data/ (7.2 data/),

  2. data-raw/ (7.4 data-raw/), and

  3. inst/extdata/ (7.5 inst/extdata/)

The applications in Chapter 7 (Data) can be accessed with the launch() or get() functions from the shinypak R package:

# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)

Chapter 7 applications:

list_apps(regex = '^07')
## # A tibble: 1 × 2
##   branch  last_updated       
##   <chr>   <dttm>             
## 1 07_data 2024-07-31 05:38:41

Launch described the differences between

  1. shinyApp() (8.2.1 shinyApp()),

  2. runApp() (8.2.3 runApp()), and

  3. shinyAppDir() (8.2.2 shinyAppDir())

This chapter also provided some options to include in app.R (8.4 The app.R file) and the standalone app function (8.3.4 Updates to launch_app()).

The applications in Chapter 8 (Launch) can be accessed with the launch() or get() functions from the shinypak R package:

# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)

Chapter 8 applications:

list_apps(regex = '^08')
## # A tibble: 1 × 2
##   branch        last_updated       
##   <chr>         <dttm>             
## 1 08_launch-app 2024-07-31 06:33:24

External files covered how to include external files and/or resources in your app (i.e., those previously stored in www/):

  1. Combining system.file() (9.1.2 system.file()) and addResourcePath() (9.1.3 addResourcePath()), and

  2. The various uses of the inst/ folder (9  External files)

    1. Alternative images and layout options (9.1.2 system.file())

    2. Development versions of your application using alternative data and modules (9.3 inst/dev)

    3. A production version of your application (9.4 inst/prod)

The applications in Chapter 9 (External files) can be accessed with the launch() or get() functions from the shinypak R package:

# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)

Chapter 9 applications:

list_apps(regex = '^09')
## # A tibble: 4 × 2
##   branch          last_updated       
##   <chr>           <dttm>             
## 1 09.1_inst-www   2024-07-31 20:42:58
## 2 09.2_inst-bslib 2024-07-31 20:55:55
## 3 09.3_inst-dev   2024-07-31 20:59:41
## 4 09.4_inst-prod  2024-08-01 07:49:39

Testing your app

We’re now ready to test the code and features in our app-package. The next section covers the following topics:

Test suite

Test suite starts by showing how to create the testthat infrastructure then, dives into creating test files, the mechanics unit tests and expectations, and running tests during development

This chapter also introduces keyboard shortcuts for testing and testthat’s behavior-driven development functions:

Specifications

Specifications discusses how to collect and organize information to write tests for your application:

This chapter also gives examples of behavior-driven development tests features and how to track specifications and tests together:

Test tools

This chapter introduces:

Each tool can contribute to testing your Shiny app-package in a unique way (they’re also relatively recent additions to the testthat framework)

Testing modules

Shiny’s testServer() function can be useful for performing integration tests with module server functions. Testing modules gives examples of using testServer() to verify module communication (i.e., passing data between modules):

System tests

The final chapter in this section covers setting up and running system (or end-to-end tests with shinytest2):

Please open an issue on GitHub