Unit testing without testthat

Viewed 266

There is one things which is wondering me. I've read something about unit testing and all I read was significantly connected with testthat (package created for unit testing). But for sure there are other approaches in R to do unit testing without using testthat package. So why they are unpopular in such level that it's even hard o find article about it ? what are the main advantages of testthat package which overwhelms unit testing market ?

1 Answers

A while back I was having the same thoughts as you. I eventually stumbled over this RBloggers article on unit testing in R.

The main reason people use packages from Hadley and the RStudio team is that they're easy to use, are well written and supported, and many of them seem to get built into RStudio desktop, which is the most popular R IDE around. Also, as @Roland says, they have the marketing advantage. On the downside, they almost always drag in a ton of dependencies. A quick look at the CRAN page for testthat shows no less than 12 required packages ("Imports"). You will find that this starts to grate a bit if you use continuous integration, and have to wait for the container OS to install them all each time. Sometimes you can cache these, but I digress. The RStudio team's packages can also be more subject to changes than many other R packages.

Sadly, as testthat is so popular, you will struggle to find guides and tutorials for any other unit testing packages. I've just switched one of my packages from testthat to a package called tinytest (mentioned in the first link). I highly recommend it. It only draws in two packages as dependencies, both of which are present in R’s core packages. It has a few less test functions than testthat, but if you can make something a logical evaluation, then expect_true() can fill the gaps. tinytest also has excellent documentation.

Related