[R] Unit Testing Frameworks: summary and brief discussion

Seth Falcon sfalcon at fhcrc.org
Thu May 10 16:21:41 CEST 2007


Hans-Peter <gchappi at gmail.com> writes:

>> - My code gives error and warning messages in some situations. I want to
>> test that the errors and warnings work, but these flags are the correct
>> response to the test. In fact, it is an error if I don't get the flag.
>> How easy is it to set up automatic tests to check warning and error
>> messages work?
>
> Maybe like this:
>
> ### for errors:
> res1fkt <- function() xls.info( exc )
> res1 <- try( res1fkt(), silent = TRUE )
> if (class( res1 ) != "try-error") stop( "xls.info, data not equal" )
> cat( "REQUIRED (EXPECTED) error message: ", res1  )

Instead, see RUnit's checkException test.  I don't see a checkWarning
test, but imagine it could be added.  Another feature that I imagine
could be added is to actually compare the error/warning message.  I'm
not sure how much benefit there is to that since it basically means
putting the error message in two places, but I suppose it can be
useful to make sure that any formatting of inputs is being done
properly.

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org



More information about the R-help mailing list