Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the current state of Unit testing support in the R language

Tags:

unit-testing

r

R is a statistics programming language. Part of R is the use of Packages, which themselves are written in the R language. Programming best practice includes the use of unit-testing to test the functions within these packages while they are being written and when they are used.

I am aware of a few packages for unit testing within R, these being

  • RUnit
  • Svunit
  • Testthat

I'm interested to know;

Are there any other packages out there ? Given peoples experience, do these packages excel at different things ? What's the current state of the art in unit testing for R ?

like image 448
PaulHurleyuk Avatar asked Mar 30 '10 18:03

PaulHurleyuk


People also ask

What is unit test in R?

The unit test basically is small functions that test and help to write robust code. From a robust code we mean a code which will not break easily upon changes, can be refactored simply, can be extended without breaking the rest, and can be tested with ease.

Is unit testing still relevant?

Unit tests are also especially useful when it comes to refactoring or re-writing a piece a code. If you have good unit tests coverage, you can refactor with confidence. Without unit tests, it is often hard to ensure the you didn't break anything.

Which testing is used for unit testing?

Unit testing uses all white box testing techniques as it uses the code of software application: Data flow Testing. Control Flow Testing. Branch Coverage Testing.


2 Answers

Unit testing seems to be more or less a solved problem, so all three packages will likely be adequate for your needs. There are subtle differences between them though:

RUnit is based on xunit, and as such is easy to understand if you've used any versions of it from other languages.

svUnit uses the same tests as RUnit, but includes a GUI to help with interactive use.

testthat isn't compatible with either, but includes much the same features and can check to only execute tests on files that haven't changed, which is useful for testing large projects.


Several years later...

RUnit and svUnit still don't have checks for messages and warnings, nor test caching, and don't seem to be under much development, so testthat should be your first choice for new projects. You can convert RUnit tests to testthat tests using my runittotestthat package.

like image 159
Richie Cotton Avatar answered Oct 05 '22 18:10

Richie Cotton


here is a few things I've found from Google.

This topic was discussed on the mailing list here which mentioned the packages above. It seems RUnit and svunit will execute the same test code, but Runit also has tracking and code coverage functions.

A comparison of the two is also on the R wiki at http://rwiki.sciviews.org/doku.php?id=developers:runit

like image 45
PaulHurleyuk Avatar answered Oct 05 '22 18:10

PaulHurleyuk