-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.qmd
469 lines (299 loc) · 10.2 KB
/
tests.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# Tests {#sec-tests .unnumbered}
```{r}
#| eval: true
#| echo: false
#| include: false
source("_common.R")
library(shinypak)
```
Expand the callout boxes below to review what we've covered in the previous chapters on debugging:
::: {.callout-note collapse='true'}
## [Exploring Code (Chapter 10)]{style='font-size: 1.35em;'}
In the [Exploring code](debug_explore.qmd) chapter we covered:
1.
2.
:::: {.callout-tip collapse='true' appearance='default'}
### [Chapter 10 Applications]{style='font-weight: bold; font-size: 1.15em;'}
::: {style='font-size: 0.95em; color: #282b2d;'}
The applications in Chapter 10 (Exploring code) can be accessed with the `launch()` or `get()` functions from the [`shinypak` R package](https://mjfrigaard.github.io/shinypak/):
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| eval: false
# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)
```
Chapter 10 applications:
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| collapse: true
list_apps(regex = '^10')
```
:::
::::
:::
::: {.callout-note collapse='true'}
## [Debugging apps (Chapter 11)]{style='font-size: 1.35em;'}
In the [Debugging apps](debug_apps.qmd) chapter we covered:
1.
2.
:::: {.callout-tip collapse='true' appearance='default'}
### [Chapter 11 Applications]{style='font-weight: bold; font-size: 1.15em;'}
::: {style='font-size: 0.95em; color: #282b2d;'}
The applications in Chapter 11 (Debugging apps) can be accessed with the `launch()` or `get()` functions from the [`shinypak` R package](https://mjfrigaard.github.io/shinypak/):
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| eval: false
# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)
```
Chapter 11 applications:
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| collapse: true
list_apps(regex = '^11')
```
:::
::::
:::
::: {.callout-note collapse='true'}
## [Print debugging (Chapter 12)]{style='font-size: 1.35em;'}
In the [Print debugging](debug_print.qmd) chapter we covered:
1.
2.
:::: {.callout-tip collapse='true' appearance='default'}
### [Chapter 12 Applications]{style='font-weight: bold; font-size: 1.15em;'}
::: {style='font-size: 0.95em; color: #282b2d;'}
The applications in Chapter 11 (Print debugging) can be accessed with the `launch()` or `get()` functions from the [`shinypak` R package](https://mjfrigaard.github.io/shinypak/):
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| eval: false
# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)
```
Chapter 12 applications:
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| collapse: true
list_apps(regex = '^12')
```
:::
::::
:::
::: {.callout-note collapse='true'}
## [Utility functions (Chapter 13)]{style='font-size: 1.35em;'}
In the [Exploring code](debug_util_funs.qmd) chapter we covered:
1.
2.
:::: {.callout-tip collapse='true' appearance='default'}
### [Chapter 13 Applications]{style='font-weight: bold; font-size: 1.15em;'}
::: {style='font-size: 0.95em; color: #282b2d;'}
The applications in Chapter 13 (Utility functions) can be accessed with the `launch()` or `get()` functions from the [`shinypak` R package](https://mjfrigaard.github.io/shinypak/):
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| eval: false
# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)
```
Chapter 13 applications:
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| collapse: true
list_apps(regex = '^13')
```
:::
::::
:::
<!--
::: {.callout-note collapse='true'}
## [Dependencies (Chapter 6)]{style='font-size: 1.35em;'}
In [Dependencies](dependencies.qmd), we walked through:
1. How to give users of our app-package access to it's functions (i.e., exports (@sec-depends-exports)), and
2. What to do with the functions we use from other packages in the `R/` folder (i.e., imports (@sec-depends-imports))
:::: {.callout-tip collapse='true' appearance='default'}
### [Chapter 6 Applications]{style='font-weight: bold; font-size: 1.15em;'}
::: {style='font-size: 0.95em; color: #282b2d;'}
The applications in Chapter 6 (Dependencies) can be accessed with the `launch()` or `get()` functions from the [`shinypak` R package](https://mjfrigaard.github.io/shinypak/):
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| eval: false
# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)
```
Chapter 6 applications:
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| collapse: true
list_apps(regex = '^06')
```
:::
::::
:::
::: {.callout-note collapse='true'}
## [Data (Chapter 7)]{style='font-size: 1.35em;'}
[Data](data.qmd) covered the three common locations for data in R packages:
1. `data/` (@sec-data-data),
2. `data-raw/` (@sec-data-data-raw), and
3. `inst/extdata/` (@sec-data-inst-extdata)
:::: {.callout-tip collapse='true' appearance='default'}
### [Chapter 7 Applications]{style='font-weight: bold; font-size: 1.15em;'}
::: {style='font-size: 0.95em; color: #282b2d;'}
The applications in Chapter 7 (Data) can be accessed with the `launch()` or `get()` functions from the [`shinypak` R package](https://mjfrigaard.github.io/shinypak/):
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| eval: false
# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)
```
Chapter 7 applications:
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| collapse: true
list_apps(regex = '^07')
```
:::
::::
:::
::: {.callout-note collapse='true'}
## [Launch (Chapter 8)]{style='font-size: 1.35em;'}
[Launch](launch.qmd) described the differences between
1. `shinyApp()` (@sec-launch-shiny-app),
2. `runApp()` (@sec-launch-run-app), and
3. `shinyAppDir()` (@sec-launch-shiny-app-dir)
This chapter also provided some options to include in `app.R` (@sec-launch-app-dot-r) and the standalone app function (@sec-launch-standalone-app-function).
:::: {.callout-tip collapse='true' appearance='default'}
### [Chapter 8 Applications]{style='font-weight: bold; font-size: 1.15em;'}
::: {style='font-size: 0.95em; color: #282b2d;'}
The applications in Chapter 8 (Launch) can be accessed with the `launch()` or `get()` functions from the [`shinypak` R package](https://mjfrigaard.github.io/shinypak/):
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| eval: false
# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)
```
Chapter 8 applications:
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| collapse: true
list_apps(regex = '^08')
```
:::
::::
:::
::: {.callout-note collapse='true'}
## [External files (Chapter 9)]{style='font-size: 1.35em;'}
[External files](external.qmd) covered how to include external files and/or resources in your app (i.e., those previously stored in `www/`):
1. Combining `system.file()` (@sec-external-system-file) and `addResourcePath()` (@sec-external-add-resource-path), and
2. The various uses of the `inst/` folder (@sec-inst)
<br>
a. Alternative images and layout options (@sec-external-system-file)
<br><br>
b. Development versions of your application using alternative data and modules (@sec-external-inst-dev)
<br><br>
c. A production version of your application (@sec-external-inst-prod)
:::: {.callout-tip collapse='true' appearance='default'}
### [Chapter 9 Applications]{style='font-weight: bold; font-size: 1.15em;'}
::: {style='font-size: 0.95em; color: #282b2d;'}
The applications in Chapter 9 (External files) can be accessed with the `launch()` or `get()` functions from the [`shinypak` R package](https://mjfrigaard.github.io/shinypak/):
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| eval: false
# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)
```
Chapter 9 applications:
```{r}
#| code-fold: false
#| message: false
#| warning: false
#| collapse: true
list_apps(regex = '^09')
```
:::
::::
:::
-->
# 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](test_suite.qmd) 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
+ @sec-tests-suite-use-testthat
+ @sec-tests-suite-use-test
+ @sec-tests-suite-test-that
+ @sec-tests-suite-expectations
+ @sec-tests-suite-running-tests
This chapter also introduces keyboard shortcuts for testing and `testthat`'s behavior-driven development functions:
+ @sec-tests-suite-keyboard-shortcuts
+ @sec-tests-suite-bdd-intro
## Specifications
[Specifications](test_specs.qmd) discusses how to collect and organize information to write tests for your application:
+ @sec-tests-specs-app-reqs
+ @sec-tests-specs-user-specs
+ @sec-tests-specs-features, and
+ @sec-tests-specs-func-reqs
This chapter also gives examples of behavior-driven development tests features and how to track specifications and tests together:
+ @sec-tests-specs-bdd-testthat
+ @sec-tests-specs-traceability-matrix
## Test tools
[This chapter](test_tools.qmd) introduces:
- @sec-test-fixtures
- @sec-test-helpers
- @sec-test-coverage-active-file, and
- @sec-test-snaps-review
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](test_modules.qmd) gives examples of using `testServer()` to verify module communication (i.e., passing data between modules):
- @sec-tests-mods-returned
- @sec-tests-mods-args-list
- @sec-tests-mods-coverage
- @sec-tests-mods-outputs
## System tests
The [final chapter](test_system.qmd) in this section covers setting up and running system (or end-to-end tests with `shinytest2`):
- @sec-tests-system-shinytest2
- @sec-tests-system-recording-tests
- @sec-tests-system-shinytest2-bdd
- @sec-tests-system-test-mode
```{r}
#| label: git_contrib_box
#| echo: false
#| results: asis
#| eval: true
git_contrib_box()
```