unitizer v1.4.3

0

Monthly downloads

0th

Percentile

Interactive R Unit Tests

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.

Readme

unitizeR - Interactive R Unit Tests

Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.

TL;DR

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.

Why Another Testing Framework?

Automated Test Formalization

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.

Streamlined Debugging

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:

diff
example

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:

review
example

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.

Usage

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:

  • 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")
  • Run unitize("my_file_name.R") and follow the prompts
  • Continue developing your package
  • Re-run 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.

Documentation

Acknowledgments

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.
  • Hadley Wickham for testthat from which we borrow many concepts and use for internal tests, for devtools, and for his outstanding contributions to the R universe.
  • Gábor Csárdi for crayon through which we can add a new dimension to the R experience.
  • Jim Hester because covr rocks.
  • 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 etal for rmarkdown, and by extension John MacFarlane for pandoc.
  • Stefan M. Bache for the idea of having a function for testing objects directly (originally vetr only worked with function arguments), which I took from ensurer.
  • Hadley Wickham for devtools, and for pointing me to Stefan M. Bache's ensurer package.
  • @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, Travis-CI, 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.

Functions in unitizer

Name Description
all.equal.condition Compare Conditions
all_eq Like all.equal but Returns Empty String If Not all.equal
unitizer_demo Demo Details and Helper Functions
desc One Line Description of Object
$,unitizerItemTestsErrorsDiffs-method Subsetting Methods for unitizerItemTestsErrorsDiffs objects
filename_to_storeid Create a Store ID from a Test File Name
mock_item Generates a Dummy Item For Use in Examples
nextItem,unitizerList-method Iterate through items of a unitizerList ObjectJK
flattenUntz Reduce S4 objects Into Lists
getFun Utility Function
set_unitizer Set and Retrieve Store Contents
show,unitizerChanges-method Print Out A Summary Of the Changes
as.character,unitizerChanges-method Print Out A Summary Of the Changes
as.character.bullet Produce Character Vector Representation of Bullet Lists
editCalls Edit Calls In Unitizer
$.unitizerItem Retrieve Test Contents From Test Item
as.expression,unitizerList-method Coerce to expression by returning items coerced to expressions
cap_first Captalizes or Decapitalizes First Letter
testthat_transcribe_file Transcribes a testtaht File Into unitizer Format
testthat_translate_file Convert a testthat Test File to a unitizer
sizeUntz Utility To Examine Object Size
testFuns Store Functions for New vs. Reference Test Comparisons
unitizerTests-class Collections of Calls For Testing
unitizer_ls An `ls` Like Function
repair_environments Repair Environment Chains
run_ls Worker function to actually execute the `ls` work
show.conditionList Prints A list of Conditions
sizeRDS Measure object size as an RDS
capture_output Capture Both StdOut and StdErr
conditionList Contains A List of Conditions
infer_unitizer_location Infers Possible Unitizer Path From Context
invalidateLs Clears ls Info and Marks as Invalid
length,unitizerChanges-method Return Sum of Total Changes
length,unitizerSection-method Compute Length of a unitizerSection-class
show,unitizerItemTestsErrorsDiff-method Show Method for unitizerItemTestsErrorsDiff objects
unitizer_prompt Interactively Retrieve User Input
unitizer_result Return Values and Related Methods for unitize Functions
show,unitizerDummy-method Documentation Block for Internal S4 Methods
unitizer_sect Define a unitizer Section
unitizerSection-class Contains Representation For a Section of Tests
unitizerState Tests and Session State
show,unitizerItemTestsErrorsDiffs-method Show Method for unitizerItemTestsErrorsDiffs objects
unitizerList S4 Object To Implement Base List Methods
valid_names Make Valid Names
unitizerGlobalBase-class Structures For Tracking Global Options
healEnvs Fix Environment Ancestries
options_zero Set Options to Initial Zero State
print.bullet Print Methods for UL and OL objects
unitizerChanges-class Summary of Changes
text_wrap Text Wrapping Utilities
unitize Unitize an R Test Script
unitizer unitizer
unitizer.opts Unitizer Options
validate_pre_post Helper function for validations
No Results!

Vignettes of unitizer

Name
styles.css
unitizer.Rmd
unitizer_index.Rmd
unitizer_interactive_env.Rmd
unitizer_miscellaneous.Rmd
unitizer_reproducible_tests.Rmd
unitizer_tests.Rmd
No Results!

Last month downloads

Details

VignetteBuilder knitr
License GPL (>= 2)
LazyData true
URL https://github.com/brodieG/unitizer
BugReports https://github.com/brodieG/unitizer/issues
Collate 'asciiml.R' 'capture.R' 'is.R' 'global.R' 'change.R' 'class_unions.R' 'list.R' 'conditions.R' 'item.R' 'deparse.R' 'text.R' 'item.sub.R' 'section.R' 'test.R' 'unitizer.R' 'exec.R' 'prompt.R' 'browse.struct.R' 'browse.R' 'demo.R' 'diff.R' 'faux_prompt.R' 'get.R' 'heal.R' 'load.R' 'ls.R' 'misc.R' 'search.R' 'options.R' 'onload.R' 'parse.R' 'rename.R' 'repairenvs.R' 'result.R' 'shims.R' 'size.R' 'state.R' 'state.compare.R' 'testfuns.R' 'translate.R' 'unitize.R' 'unitize.core.R' 'unitizer-package.r' 'unitizer.add.R' 'upgrade.R'
RoxygenNote 6.0.1
NeedsCompilation no
Packaged 2017-06-08 01:41:22 UTC; brodie
Repository CRAN
Date/Publication 2017-06-08 11:52:21 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/unitizer)](http://www.rdocumentation.org/packages/unitizer)