-
Notifications
You must be signed in to change notification settings - Fork 0
/
series.qmd
85 lines (62 loc) · 6.08 KB
/
series.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
title: "Series"
listing:
- id: testing
contents: series/testing
type: table
sort: "date asc"
sort-ui: false
filter-ui: false
fields: [title, subtitle]
table-striped: true
# - id: shiny-frameworks
# contents: series/shiny-frameworks
# type: table
# sort: "date asc"
# sort-ui: false
# filter-ui: false
# fields: [title, subtitle]
# table-striped: true
page-layout: full
title-block-banner: false
execute:
freeze: auto
---
## Testing shiny apps
These posts focus on testing Shiny applications with `testthat`, `shiny`'s `testServer()` function, and `shinytest2`.
::: {#testing}
:::
::: {.callout-note collapse="true" title="Testing details"}
::: {style="font-size: 1.02em"}
- [**`testthat`**]{style="font-size: 1.20em"}: `testthat` is a popular unit testing framework that allows R package developers to create tests scripts for functions and logic systematically. In a shiny app-package, it's used for testing the non-reactive components (i.e., utility functions). This includes functions for data processing, plots, modeling, and other code that's part of the package. However, it is not designed to work with shiny's reactive model.
- **Post: Unit testing shiny utility functions**: This post covers unit testing a set of utility functions with testthat. You can also read the documentation from the [package website](https://testthat.r-lib.org/), in [R packages](https://r-pkgs.org/testing-basics.html), and in [Mastering Shiny](https://mastering-shiny.org/scaling-testing.html). The app-package for this post is stored in [this Github Repo](https://github.com/mjfrigaard/utap).
- **Post: Unit tests for (non-package) shiny apps**: Your shiny app *should* be developed as a package, but this isn't always the case. If you'd like to test your application's code *without* converting it to a package, check out the second post ([GitHub repo](https://github.com/mjfrigaard/noap) with the code).
- [**`testServer()`**]{style="font-size: 1.20em"}: `testServer()` comes from the shiny package and is designed to test the `server`-side logic of your app. These tests can be used to simulate user inputs and verify the corresponding outputs. `testServer()` can also test the functionality of module `server` functions (reactivity, outputs, and any returned values) in isolation from their UI function counterparts. However, `testServer()` doesn't capture how UI elements are rendered or simulate key user interactions (i.e., execution paths) through the application.
- **Post: Testing shiny module server functions**: If you've built your shiny application as a package and it contains modules, this post covers testing module server functions using the examples from the ['Modules' chapter of Mastering Shiny](https://mastering-shiny.org/scaling-modules.html). The code and examples are in [this GitHub repo](https://github.com/mjfrigaard/mstsap)
- [**`shinytest2()`**]{style="font-size: 1.20em"}: `shinytest2` is designed to perform end-to-end testing of shiny apps. These tests can capture a shiny app's current state (i.e., a snapshot) and compare it with a previously saved (or expected) states. Snapshots are useful for end-to-end testing because they can simulate key user interaction in a way that unit tests and `testServer()` can't (i.e., the delay between input changes and rendering updated outputs, specific sequences of selections on action buttons, radio buttons, etc.). `shinytest2` tests are resource-intensive, so it's recommended to write these tests after writing `testthat` unit tests and `testServer()` tests.
- **Post: Testing shiny apps with `shinytest2`**: This post picks up where the previous post left off with the [`shinytest2` package](https://rstudio.github.io/shinytest2/index.html). The app-package used in the examples is stored in [this GitHub repo](https://github.com/mjfrigaard/msst2ap).
In summary, use `testthat` for unit testing utility/helper functions, then `testServer()` for the server-side logic, and finish off with `shinytest2` tests for end-to-end functionality of your shiny app. These tools complement each other to provide a comprehensive testing framework.
:::
:::
<!--
## Shiny frameworks
This series covers building shiny app-packages with [`devtools`](https://mastering-shiny.org/scaling-packaging.html) and other popular shiny frameworks ([`golem`](https://thinkr-open.github.io/golem/), [`rhino`](https://appsilon.github.io/rhino/), and [`leprechaun`](https://leprechaun.opifex.org/#/)).
::: {#shiny-frameworks}
:::
::: {.callout-note collapse="true" title="shiny frameworks"}
::: {style="font-size: 1.02em"}
:::
:::
## Other projects
| Project | Description | Purpose |
|-----------|--------------------------------------------|-----------------------------------------------------------------------------|
| `duap` | `devtools`/`usethis` app-package | Demonstrates building an app-package with standard R package tools |
| `gap` | `golem` app-package | Demonstrates `golem` framework |
| `rnap` | `rhino` app-non-package | Demonstrates `rhino` framework (and `box`) |
| `utap` | Unit testing app-package | Demonstrates testing utility functions in shiny app-package. |
| `mstsap` | Mastering Shiny `testServer()` app-package | Demonstrates using shiny's `testServer()` function for integration testing. |
| `msst2ap` | Mastering Shiny `shinytest2` app-package | Demonstrates using `shinytest2` for end-to-end testing |
| `lap` | `leprechaun` app-package | Demonstrates `leprechaun` framework in an app-package |
| `dbsap` | Debugging shiny app-package | |
| | | |
-->