Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #302 Adding Snapshot testing guidance to unit testing vignette #308

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Common R CMD troubleshooting made into separate vignette (#286)
- Documentation of `get_dataset()` was improved. (#271)
- Minor updates to programming strategy were added (#213, #240, #260)
- Updated unit testing vignette with snapshot testing guidance. (#302)

## Various

Expand Down
13 changes: 13 additions & 0 deletions vignettes/unit_test_guidance.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ your function justifies it, e.g. see the test script: https://github.com/pharmav

Don’t forget to add a unit test for each exported function.

## Snapshot Testing

Standard unit tests are not always convenient to record the expected behavior with code.
Some challenges include:

- Output that is large, making it painful to define the reference output, and bloating the size of the test file and making it hard to navigate.
- Text output that includes many characters like quotes and newlines that require special handling in a string.
- Binary formats like plots or images, which are very difficult to describe in code: i.e. the plot looks right, the error message is useful to a human, the print method uses color effectively.

For these situations, testthat provides an alternative mechanism: snapshot tests.
Snapshot tests record results in a separate human readable file and records the results, including output, messages, warnings, and errors.
Review the [{testthat} snapshot vignette](https://testthat.r-lib.org/articles/snapshotting.html) for details.

## Set up the Test Script

Within the `tests/testthat` folder of the project, add a script with the naming
Expand Down
Loading