diff --git a/NEWS.md b/NEWS.md index bfd323a2..8511f714 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/vignettes/unit_test_guidance.Rmd b/vignettes/unit_test_guidance.Rmd index b85a3287..45ad4f8f 100644 --- a/vignettes/unit_test_guidance.Rmd +++ b/vignettes/unit_test_guidance.Rmd @@ -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