Skip to content

Commit ca4c19e

Browse files
committed
Polish
1 parent 6122a11 commit ca4c19e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

vignettes/challenging-tests.Rmd

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ If your function depends on options or environment variables, first try refactor
2828

2929
## Random numbers
3030

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")`.
3232

3333
```{r}
3434
#| label: random-local-seed
@@ -46,7 +46,7 @@ test_that("dice returns different numbers", {
4646
})
4747
```
4848

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")`.
5050

5151
```{r}
5252
#| label: random-mock
@@ -67,7 +67,7 @@ If you're trying to test functions that rely on HTTP requests, we recommend usin
6767

6868
## User interaction
6969

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:
7171

7272
```{r}
7373
#| label: continue
@@ -136,6 +136,8 @@ test_that("save_file() requires confirmation to overwrite file", {
136136
})
137137
```
138138

139+
Learn more in `vignette("mocking")`.
140+
139141
## User-facing text
140142

141-
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

Comments
 (0)