[Rd] unit testing framework for R?

A.J. Rossini rossini at blindglobe.net
Thu Mar 18 00:57:46 MET 2004


"Paul Gilbert" <pgilbert at bank-banque-canada.ca> writes:

> I am interested in this, but there is already a fair amount that can
> be accomplished within the existing framework. I do something I think
> of as unit testing, but my code chunks are packages rather than
> functions. This does not have to be reactive. With a proper makefile
> setup it can be proactive.

Correct -- it's the interface.

> Within a package it should be possible to reflect some of the
> dependancy structure simply by a naming convention like tests/01test,
> tests/02othertest, tests/03moretests ....

That would be the next step -- what we actually do is have functions
in the tests/ directory, along with a possible external flag variable
which if bound, disables the automatic evaluation of the functions and
instead lets one pick a suite of functions.

So our hacks are basically:

1. use a possibly bound variable to determine if we evaluate
everything (CMD check) or just pieces (test(c(1,2,10))

2. create an instance of a class that describes this.

3. have methods for the class that automate the evaluation.

> I am not sure how much will be gained by automatically generating
> comparison files for the tests. Most of my tests are based on
> computing numeric values, doing a comparison with known values, and
> executing stop()if there is a problem. If you could generate those
> kind of comparisons automatically, then that would be terrific.

I'm not constructing comparison files for the tests -- I'm
testing results against previous stored results and returning a
boolean value indicating if there is a pass.

And its a hack since we don't do it automagically (or rather,
automagically via a "sample" observation of the function's parse
tree).

One of these days I'll clean it up, but I suspect that someone will
implement it right before I get around to it (post Bioconductor
release).

best,
-tony

-- 
rossini at u.washington.edu            http://www.analytics.washington.edu/ 
Biomedical and Health Informatics   University of Washington
Biostatistics, SCHARP/HVTN          Fred Hutchinson Cancer Research Center
UW (Tu/Th/F): 206-616-7630 FAX=206-543-3461 | Voicemail is unreliable
FHCRC  (M/W): 206-667-7025 FAX=206-667-4812 | use Email

CONFIDENTIALITY NOTICE: This e-mail message and any attachme...{{dropped}}



More information about the R-devel mailing list