unitizeR - Interactive R Unit Tests
unitizer simplifies creation, review, and debugging of tests in R. It
automatically stores R expressions and the values they produce, so
explicit expectations are unnecessary. Every test is easy to write with
unitizer because testing and using a function are the same. This
encourages non-trivial tests that better represent actual usage.
Tests fail when the value associated with an expression changes. In interactive mode you are dropped directly into the failing test environment so you may debug it.
unitizer is on CRAN:
It bakes in a lot of contextual help so you can get started without reading all the documentation. Try the demo to get an idea:
Or check out the
unitizer in action.
Why Another Testing Framework?
Automated Test Formalization
Are you tired of the
dput then copy-paste R objects into
test file dance, or do you use
other snapshot testing a lot?
unitizer you interactively review your code as you would when
typing it at the R prompt. Then, with a single keystroke, you tell
unitizer to store the code, and any values, warnings, or errors it
produced, thereby creating a formal regression test.
Do you wish the nature of a test failure was more immediately obvious?
When tests fail, you are shown a proper diff so you can clearly identify how the test failed:
Do you wish that you could start debugging your failed tests without additional set-up work?
unitizer drops you in the test environment so you can debug why the
test failed without further ado:
Fast Test Updates
Do you avoid improvements to your functions because that would require painstakingly updating many tests?
The diffs for the failed tests let you immediately confirm only what you intended changed. Then you can update each test with a single keystroke.
unitizer stores R expressions and the result of evaluating them so
that it can detect code regressions. This is akin to saving test output
.Rout.save file as documented in Writing R
except that we’re storing the actual R objects and it is much easier to
- Write test expressions as you would when informally testing code on the command line, and save them to a file (e.g. “my_file_name.R”).
unitize("my_file_name.R")and follow the prompts.
- Continue developing your package.
unitize("my_file_name.R"); if any tests fail you will be able to review and debug them in an interactive prompt.
unitizer can run in a non-interactive mode for use with
R CMD check.
help(package="unitizer"), in particular
browseVignettes("unitizer")for a list of vignettes, or skip straight to the Introduction vignette
Thank you to:
- R Core for developing and maintaining such a wonderfully language.
- CRAN maintainers, for patiently shepherding packages onto CRAN and maintaining the repository, and Uwe Ligges in particular for maintaining Winbuilder.
- Gábor Csárdi for crayon through which we can add a new dimension to the R experience.
- Jim Hester because covr rocks.
- Hadley Wickham for testthat from which we borrow many concepts, and for his many other packages.
- Dirk Eddelbuettel and Carl Boettiger for the rocker project, and Gábor Csárdi and the R-consortium for Rhub, without which testing bugs on R-devel and other platforms would be a nightmare.
- Yihui Xie for knitr and J.J. Allaire et al. for rmarkdown, and by extension John MacFarlane for pandoc.
- @kohler for gifsicle and the ffmpeg team for ffmpeg.
- All open source developers out there that make their work freely available for others to use.
- Github, Codecov, Vagrant, Docker, Ubuntu, Brew for providing infrastructure that greatly simplifies open source development.
- Free Software Foundation for developing the GPL license and promotion of the free software movement.
About the Author
Brodie Gaslam is a hobbyist programmer based in the US East Coast.