Hadley Wickham's testthat package has been a boon for R package authors, making it easy to write tests to verify that your code is working directly, and alerting you when you make changes to your code that inadvertently breaks things.
For the RHadoop project, though, developer Antonio Piccolboni needed a different testing framework, that included the possibility of writing tests that included random input values for functions. The Haskell language has a "quickcheck" package that does this, so Antonio wrote a similar package for R, also called quickcheck. The key function is called (naturally) test, and here's an example of it in action, testing a user-defined function called "identity":
test(function(x = rinteger()) identical(identity(x), x), sample.size = 100)
The rany function generates random integer inputs to pass to the identity function, and in this case the test is run 100 times with random values. Quickcheck supports generating inputs of various R data types (double, character, etc) and can even generate a mixture of R object types to test functions that support inputs of multiple types. And when errors are detected, the function repro will tell you exactly what inputs generated the error so you can track it down.
The quickcheck package is available for download now from GitHub, and a great place to start is the quickcheck tutorial, linked below.
Github (quickcheck): Assertion-based testing with Quickcheck
Comments
You can follow this conversation by subscribing to the comment feed for this post.