Having used JUnit and PyUnit, I was pleased to see the release of the RUnit package on CRAN. I'm wondering if there are any RUnit users out there that would be willing to share some tips on how they organize their code to work with RUnit. Specifically, I'm wondering about the best way to load/import/source the functions to be tested. I would like to end up with a script, testall or some such, that allows me to run all the unit tests in a given directory. One way I've thought about looks like: myfunc.R -------------- # some functions here -------------- runit_myfunc.R -------------- source("myfunc.R") # test function here -------------- + seth
Seth Falcon <sfalcon at fhcrc.org> writes:> Having used JUnit and PyUnit, I was pleased to see the release of the > RUnit package on CRAN. > > I'm wondering if there are any RUnit users out there that would be > willing to share some tips on how they organize their code to work with > RUnit. > > Specifically, I'm wondering about the best way to load/import/source the > functions to be tested. I would like to end up with a script, testall > or some such, that allows me to run all the unit tests in a given > directory.Hi Seth - The version that I was working on (before the other folks released a less eclectic and more functional/general package) had a testrunner(test=c("list","of","functions"),testall=FALSE) API, along with a preliminary tcltk GUIrunner() with a similar intended API. I've been trying to find the initiative to integrate (overlay) those tools with the current RUnit as an add-on, but the difference is that I attached tests as S4 object instantiations. Stop by if you want to chat a bit about it. best, -tony -- Anthony Rossini Research Associate Professor 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}}
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 -- Klaus Juenemann Software Engineer/ Biostatistician Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany phone:+49-30-24345-393 fax:+49-30-24345-555 http://www.epigenomics.com klaus.juenemann at epigenomics.com