Skip to content

Approaches to using RUnit

2 messages · Klaus Juenemann, Seth Falcon

#
Hi Seth,

first of all note that it was a deliberate decision to leave it up to 
the RUnit user to load all the functions and packages to be tested 
because loading and sourcing is always very site-specific. RUnit just 
assumes that all functionality to be tested is already present in the R 
session.

If you don't organize your code into packages but source individual R 
files your approach to source the code at the beginning of a test file 
looks the right thing to do.

We mainly use packages and the code we use to test packages A and B, 
say, looks like this:

library("A")
library("B")
testsuite.A <- defineTestSuite("A", "location_of_package_A/tests")
testsuite.B <- defineTestSuite("B", "location_of_package_B/tests")
testresult <- runTestSuite(list(testsuite.A, testsuite.B))
printHTMLProtocol(testresult, "location_of_testProtocol")

We use the tests subdirectory of a package to store our RUnit tests even 
though this is not really according to R conventions.

The nice thing is that this code can be executed in batch mode from a 
shell script. This script is executed nightly (and before starting R 
checks out and installs the packages from CVS). In this way, we know the 
test status of our code every morning.


Hope this helps,
Klaus
2 days later
#
On Tue, Aug 10, 2004 at 04:53:49PM +0200, Klaus Juenemann wrote:
Appears to be working pretty well for me too ;-)
SNIP
In an off list exchange with A.J. Rossini, we discussed an alternative
for using RUnit in a package.  The idea was to put the runit_*.R files
(containing test code) into somePackage/inst/runit/ and then put a
script, say dorunit.R inside somePackage/test/ that would create the
test suite's similar to the code you included in your mail.  The
advantage of this would be that the unit tests would run using R CMD
check.

In the next week or so I hope to package-ify some code and try this out.  


+ seth