[R] Test Driven Development in R

Spencer Graves spencer.graves at prodsyse.com
Sat Jan 31 17:48:16 CET 2009


Hi, Jose: 

      How does the following

      I have not studied "Test Driven Development", but I routinely 
write documentation "*.Rd" files before I write code, and the 
documentation files include test cases in the "\examples" section.  With 
"\dontshow", I hide tests that I don't think would benefit a user. 

      The source for the 'fda' package includes numerous constructions 
like the following: 


\dontshow{stopifnot(}
all.equal(fRegressout, knee.hip.f)
\dontshow{)}


      Here, "fRegressout" and "knee.hip.f" are two different objects 
that should theoretically be equal.  I show the user that they are in 
fact equal, but I don't bother the user with the "stopifnot" call that 
will stop "R CMD check" to let me know that the code fails this test.  I 
have not used "Runit", but it's on my "to do" list.  "Sciviews-K" sounds 
interesting, but I have not used it. 

      Also, Chambers (2008) Software for Data Analysis (Springer) says 
that "trustworthy software" is "The Prime Directive".  TDD sounds like 
it would support that goal. 

      I will not be able to attend useR 2009 but would be interested in 
a further discussion of this issue. 

      Best Wishes,
      Spencer Graves  

Tobias Verbeke wrote:
> Jose Quesada wrote:
>
>> Hi,
>> I wonder what kind of interest there is on Test Driven Development 
>> (TDD) in R.
>>
>> Test Driven Development consists of writing the test before the 
>> function, and iteratively build the function until it passes the test.
>>
>> Python and Ruby (specially Ruby) have very strong test-oriented 
>> cultures. In fact, in Ruby at least the custom is to do TDD and 
>> lately Behavior-driven development (BDD). In BDD, one writes a story 
>> of what one would want the code to do. This story is almost native 
>> English, and then the test suite converts it into something that the 
>> language understand as tests.
>>
>> There are some posts on the list about this, but they are about 
>> testing in general (Runit), not TDD. Example:
>> http://thread.gmane.org/gmane.comp.lang.r.general/85047
>>
>> Recently, I found there is an alpha, but working implementation of 
>> TDD for Komodo edit:
>> www.sciviews.org/SciViews-K/index.html
>>
>> The editor has a green bar that becomes red as soon as one edits a 
>> function, and that edit breaks the tests. This is tremendously useful.
>>
>> Using Gmane search, the only mention I could find on svUnit was:
>> http://thread.gmane.org/gmane.comp.lang.r.general/136632/focus=136662
>>
>> I think this could make a great UseR 2009 talk. Ideally, by someone 
>> with more R experience than me, and even more ideally by Philippe 
>> Grosjean :), but it push comes to shove, I could prepare such a talk.
>>
>> Would this be interesting at all? Are there any resources that I have 
>> missed? 
>
> There is the RUnit package which is a mature xUnit implementation for R.
>
> I don't know of a tight integration into an editor (apart from
> that it is _planned_ for StatET, the Eclipse R plug-in), but
> as such it is very useful already.
>
> http://cran.r-project.org/web/packages/RUnit/index.html
>
> HTH,
> Tobias
>
> ______________________________________________
> R-help at r-project.org 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.
>




More information about the R-help mailing list