From 3598c9381e52eaffbc2f7316966f960dbdd2de8e Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Mon, 31 Jul 2023 06:45:29 -0700 Subject: [PATCH 1/3] Update unit_test_guidance.Rmd --- vignettes/unit_test_guidance.Rmd | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 From a76b5e74b821402595d280471f9c5e4debadc96e Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Mon, 31 Jul 2023 06:53:48 -0700 Subject: [PATCH 2/3] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 53b93dfe..6a9fc08d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. (#320) ## Various From fc48654184b4ddac9c958afc37ce47f04c090676 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Mon, 31 Jul 2023 06:57:18 -0700 Subject: [PATCH 3/3] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 6a9fc08d..5f7d7cb0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,7 +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. (#320) +- Updated unit testing vignette with snapshot testing guidance. (#302) ## Various