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 basics) 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-01 12:43:17

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-01 13:11:10
## 2 06.2_pkg-imports 2024-07-01 22:14:03

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-01 22:16:06

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 app.R options) and the standalone app function (8.3.4 Updated 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-01 22:19:12

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 dev data app)

    3. A production version of your application (9.4 Production (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-01 22:22:47
## 2 09.2_inst-bslib 2024-07-01 22:27:04
## 3 09.3_inst-dev   2024-07-01 22:37:26
## 4 09.4_inst-prod  2024-07-01 22:39:44

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 (10.2 Setting up testthat tests) then, dives into

This chapter also introduces keyboard shortcuts for testing (10.3.6 Keyboard shortcuts) and testthat’s behavior-driven development functions (10.3.4 BDD test functions).

Specifications

Specifications discusses how to collect and organize 11.1 Application requirements, 11.1.1 User Specifications, 11.1.2 Features, and 11.1.3 Functional Requirements.

This chapter also gives example descriptions of features and scenarios with 11.3 BDD and testthat, and how to track specifications and tests in a 11.4 Traceability Matrix.

Test tools

This chapter introduces test 12.1 Test fixtures, 12.2 Test helpers, 12.2.2 Test development, and 12.3.1 Reviewing _snaps/. 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