Simplifies regression tests by comparing objects produced by test code with earlier versions of those same objects. If objects are unchanged the tests pass, otherwise execution stops with error details. If in interactive mode, tests can be reviewed through the provided interactive environment.
unitizer
simplifies creating, reviewing, and debugging unit tests in R. To install:
install.packages('unitizer')
Please keep in mind this is an experimental framework that has been thoroughly tested by one person.
unitizer
bakes in a lot of contextual help so you can get started without reading all the documentation. Try the demo to get an idea:
library(unitizer)
demo(unitizer)
Or check out the screencast to see unitizer
in action.
Are you tired of the deparse
/dput
then copy-paste R objects into test file
dance, or do you use testthat::expect_equal_to_reference
a lot?
With unitizer
you review function output at an interactive prompt as you
would with informal tests. You then store the value, conditions (e.g.
warnings, etc.), and environment for use as the reference values in formal
tests, all with a single keystroke.
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:
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 to a
.Rout.save
file as documented in Writing R
Extensions,
except that we're storing the actual R objects and it is much easier to review
them.
To use unitizer
:
unitize("my_file_name.R")
and follow the promptsunitize("my_file_name.R")
; if any tests fail you will be able to
review and debug them in an interactive promptunitizer
can run in a non-interactive mode for use with R CMD check
.
help(package="unitizer")
, in particular ?unitize
demo(package="unitizer")
browseVignettes("unitizer")
for a list of vignettes, or skip straight to the Introduction vignetteThank you to:
Brodie Gaslam is a hobbyist programmer based in the US East Coast.
unitizer
NEWSinstall.packages
calls in tests now use a temporary folder for library.RNGversion()
in internal tests due to changes to R sampling mechanism.devtools
as a
suggests dependency (reported by @jimhester).q()
actually works
now.diffObj
call in try
to avoid killing unitizer
section when
diffObj
errors.test_dir
calls to use wrap
on testthat
versions greater than
0.1.2..Last.value
does not workunitizers
generated by later versions of the package in earlier version of
the packages provided the object validatesFixing CRAN submission errors.
First Release to CRAN.
Interim release to get changes over past year out on the master branch.
QQ
q()
or
quit()
by mistake you can now cancel that action before unitizer
terminates unceremoniouslyunitize
and unitize_dir
without specifying any arguments (infer from
working directory)unitizer
REPL.DIFF
and .diff
tools:rstudio
, and many othersbase.env
now unique for each unitizer
debug
is usable againRdiff_obj
to run a tools::Rdiff
directly on two R objectsunitizer
stores
107, 106, 104, 103, 101, 99, 98, 94, 93, 90, 85, 84, 77, 74, 71, 67, 127, 115, 132, 134
unitize_dir
behavior (#51)testthat
-> unitizer
translation utilities
(see ?testthat_translate_file
)unitize_dir
and unitize
by
default auto-preload files in subdir 'helper'env.clean
to par.env
(technically API breaking, but since no
one is using this package yet...)unitize_dir
works with empty dirs (#78)review
now properly infers unitizer locationsunitize
can now infer partially specified test file names (in particular,
will know to look in pkgname/tests/unitizer
; see ?infer_unitizer_location
)parse_with_comments
no longer run in non-interactive mode (#63)show
method (#54)unitizer_sect
preserved (#64)search_path_cleanup
more robust (#59)get_text_capture
tests added (#60)editFunNames
becomes editCalls
and provides more comprehensive editing of
calls (Issue #52)get*
functions, instead, access test details with .NEW
/.REF
(Issue #29)editFunNames
to allow user to modify stored calls in unitizer
so that tests can be re-used even if function names are changedDoc updates; should have been part of 0.6.4, but was too rushed to push...
review
mode (issue #43)traceback()
now works for stop(simpleError(...))
type stopsBehavior changes:
Minor release, no substantive changes.
unitizer
no longer automatically modifies it through upgrade
upgrade
cleaned up and has tests nowpkg::fun
or pkg:::fun
no longer causes problems
when checking for ignorednessget
no longer warns if unitizer
ids don't matchdemo(unitizer)
)unitize_dir
allows you to run all tests in a directory (issue #24)review
allows you to review and drop tests from an existing unitizer
store
(issue #21)unitize(..., force.update=TRUE)
will overwrite unitizer even if there were
no changes recorded (issue #19)unitize
now runs with search.path.clean=TRUE
by defaultSummary titles cleaned up, interative prompts made clearer, package reload warn conflicts quieted (d2fe594c747, #23)
unitize(..., search.path.clean=TRUE)