You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/challenging-tests.Rmd
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ If your function depends on options or environment variables, first try refactor
28
28
29
29
## Random numbers
30
30
31
-
Random number generators generate different numbers each time you can them because they update a special `.Random.seed` variable. You can temporarily set this seed to a known value to make your random numbers reproducible with `withr::local_seed()`, making random numbers a special case of test fixtures.
31
+
Random number generators generate different numbers each time you can them because they update a special `.Random.seed` variable stored in the global environment. You can temporarily set this seed to a known value to make your random numbers reproducible with `withr::local_seed()`, making random numbers a special case of test fixtures. Learn more in `vignette("test-fixtures")`.
32
32
33
33
```{r}
34
34
#| label: random-local-seed
@@ -46,7 +46,7 @@ test_that("dice returns different numbers", {
46
46
})
47
47
```
48
48
49
-
Alternatively, you might want to mock your function that wraps a random number generator:
49
+
Alternatively, you might want to mock the function to eliminate randomness. Learn more in `vignette("mocking")`.
50
50
51
51
```{r}
52
52
#| label: random-mock
@@ -67,7 +67,7 @@ If you're trying to test functions that rely on HTTP requests, we recommend usin
67
67
68
68
## User interaction
69
69
70
-
If you're testing a function that relies on user feedback from `readline()` or `menu()` or similar, you can use mocking (`vignette("mocking")`) to temporarily make those functions return fixed values. For example, imagine that you have the following function that asks the user if they want to continue:
70
+
If you're testing a function that relies on user feedback from `readline()` or `menu()` or similar, you can use mocking to temporarily make those functions return fixed values. For example, imagine that you have the following function that asks the user if they want to continue:
Errors, warnings, and other user-facing text should be tested to ensure they're helpful and consistent. Obviously you can't test this 100% automatically, but you can ensure that such messaging is clearly shown in PRs, so another human can take a look. This is exactly the point of snapshot tests; learn more in `vignette("snapshotting")`.
143
+
Errors, warnings, and other user-facing text should be tested to ensure they're consistent and actionable. Obviously you can't test this 100% automatically, but you can ensure that such messaging is clearly shown in PRs so another human can take a look. This is point of snapshot tests; learn more in `vignette("snapshotting")`.
0 commit comments