In a quick search of the R website just now, I found no mention of a unit testing framework for R. I hope to find something in the style of Java's JUnit, or Python's unittest. Is such a thing available? Thanks, - Paul Shannon Institute for Systems Biology Seattle
Paul Shannon <pshannon@systemsbiology.org> writes:> In a quick search of the R website just now, I found no mention of > a unit testing framework for R. I hope to find something > in the style of Java's JUnit, or Python's unittest. Is such a > thing available?Paul - I've got a first pass at such a thing, but it isn't clear what the right "general purpose" solution is (currently, it consists of a set of S4 classes which allow for comparison of results for functions -- could be easily extended for S4 methods and classes, but havn't had time to think it through. best, -tony -- rossini@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}}
Packages can have a 'tests' directory, which can contain foo.R and foo.Rout.save files. When packages are built (or checked) the output from running R with the commands in foo.R is compared with foo.Rout.save, and differences are reported. The "Writing R Extensions" manual discusses this a little. It suggests: "Use R CMD check --help (Rcmd check --help on Windows) to obtain more information about the usage of the R package checker. A subset of the checking steps can be selected by adding flags." I've considered looking at several enhancements of the testing features: (1) automatically construct foo.R from foo.Rout.save (easy if the file only contains simple commands issued at the standard prompt); (2) allow specification of which test files to run; and (3) print summaries of test successes and failures at the end of running the selected tests. Is there any wider interest in such features? -- Tony Plate At Wednesday 11:11 AM 3/17/2004, Paul Shannon wrote:>In a quick search of the R website just now, I found no mention of >a unit testing framework for R. I hope to find something >in the style of Java's JUnit, or Python's unittest. Is such a >thing available? > >Thanks, > > - Paul Shannon > Institute for Systems Biology > Seattle > >______________________________________________ >R-devel@stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-devel
Tony 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. 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 .... 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. Paul Gilbert -----Original Message----- From: A.J. Rossini [mailto:rossini@blindglobe.net] Sent: Wed 3/17/2004 4:21 PM To: Tony Plate Cc: r-devel@stat.math.ethz.ch Subject: Re: [Rd] unit testing framework for R? Tony Plate <tplate@blackmesacapital.com> writes:> How would a "unit testing" framework look different? (other than > maybe the ability to pick and choose tests easily and run them > quickly).That is precisely it -- i.e. it's all testing, but it depends on where and how the tests are intended. (and then, how easy it is to write tests and run them..). The basic principle for unit tests is that you can associate a test with a particular unit of code, and relate the ability to run it to the function. So, one approach is to use the tests directory, with a file for each function with tests, and then have a means to test. This is reasonably easy to do. The other issue is the ability to group tests by dependencies (again, more of a UI functionality than a real problem). So, I think the point I'm trying to hammer at is the interface, not whether a framework which can be adopted is already in place. best, -tony -- rossini@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}} ______________________________________________ R-devel@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-devel [[alternative HTML version deleted]]