[R] Unit Testing Frameworks: summary and brief discussion

Martin Morgan mtmorgan at fhcrc.org
Wed May 9 20:18:59 CEST 2007


Oops, taking a look at the unit tests in RUnit, I see that specifying
'where=.GlobalEnv' is what I had been missing.

testCreateClass <- function() {
    setClass("A", contains="numeric", where=.GlobalEnv)
    a=new("A")
    checkTrue(validObject(a))
    removeClass("A", where=.GlobalEnv)
    checkException(new("A"))
}

Executing test function testCreateClass  ...  done successfully.

RUNIT TEST PROTOCOL -- Wed May  9 11:11:27 2007 
*********************************************** 
Number of test functions: 1 
Number of errors: 0 
Number of failures: 0 

Sorry for the noise. Martin

Martin Morgan <mtmorgan at fhcrc.org> writes:

> ml-r-help at epigenomics.com writes:
>
>> anthony.rossini at novartis.com wrote:
>> [...]
>>> ============= From Seth Falcon:
>>>   1. At last check, you cannot create classes in unit test code and
>>>      this makes it difficult to test some types of functionality.  I'm
>>>      really not sure to what extent this is RUnit's fault as opposed
>>>      to limitation of the S4 implemenation in R.
>>
>> I'd be very interested to hear what problems you experienced. If you 
>> have any example ready I'd be happy to take a look at it.
>> So far we have not observed (severe) problems to create S4 classes and 
>> test them in unit test code. We actually use RUnit mainly on S4 classes 
>> and methods. There are even some very simple checks in RUnits own test 
>> cases which create and use S4 classes. For example in tests/runitRunit.r
>> in the source package.
>
> RUnit has been great for me, helping to develop a more rigorous
> programming approach and gaining confidence that my refactoring
> doesn't (unintentionally) break the established contract.
>
> One of the strengths of unit tests -- reproducible and expressible in
> the way that language sometimes is not:
>
> testCreateClass <- function() {
>     setClass("A", contains="numeric")
>     checkTrue(TRUE)
> }
>
>
> RUNIT TEST PROTOCOL -- Wed May  9 10:36:53 2007 
> *********************************************** 
> Number of test functions: 1 
> Number of errors: 1 
> Number of failures: 0 
>
>  
> 1 Test Suite : 
> CreateClass_test - 1 test function, 1 error, 0 failures
> ERROR in testCreateClass: Error in assign(mname, def, where) : cannot add bindings to a locked environment
>
>> sessionInfo()
> R version 2.6.0 Under development (unstable) (2007-05-07 r41468) 
> x86_64-unknown-linux-gnu 
>
> locale:
> LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=en_US;LC_MONETARY=en_US;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C
>
> attached base packages:
> [1] "tools"     "stats"     "graphics"  "grDevices" "utils"     "datasets" 
> [7] "methods"   "base"     
>
> other attached packages:
>    RUnit
> "0.4.15"
>
> -- 
> Martin Morgan
> Bioconductor / Computational Biology
> http://bioconductor.org
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Martin Morgan
Bioconductor / Computational Biology
http://bioconductor.org



More information about the R-help mailing list