Skip to content

Commit

Permalink
Closes #302 Adding Snapshot testing guidance to unit testing vignette (
Browse files Browse the repository at this point in the history
…#308)

* Update unit_test_guidance.Rmd

* Update NEWS.md

* Update NEWS.md
  • Loading branch information
ddsjoberg committed Aug 2, 2023
1 parent 4f9d68b commit 4f6350e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
- Guidance around issues and merging updated (#286)
- 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)
- Documentation of `friendly_type_of()` was provided (#22)
- Minor updates to programming strategy were added (#181, #213, #240, #260)
- Minor updates to pull request review guidance were added (#201, #292)

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

0 comments on commit 4f6350e

Please sign in to comment.