tinytest 1.2.0 is on CRAN

[This article was first published on R – Mark van der Loo, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

tinytest is a relatively new, light-weight (no-dependency) but full-featured unit testing framework for R. It is currently used by 60+ packages, including the famous Rcpp package.

onwards to the tinyverse

The latest version of tinytest was accepted by CRAN on 5 May 2020. This is a minor release with some fixes and a few new features.

New features

tinytest now gives you some extra control over the environment the tests are un in. The workhorse function run_test_file now has an argument set_env, so you can do

run_test_file("test_mypkg.R", set_env=list(LC_TIME = "nl_NL.utf8", FOO="bar"))

and your time locale settings will be Dutch during the time of your test run (and who wouldn’t want that?). Also your FOO will be bar, but only during the test run. All functions that rely on run_test_file get the same argument via the ....

You can now compare output to stored output using expect_equal_to_reference() and expect_equivalent_to_reference(). This compares a value to a value stored in and RDS file.

There’s a new function expect_stdout() that catches everything that is printed or cat’ed to the terminal. The expect_message() function used to do this, but this task is now split over two functions, making the interface somewhat more consistent.

The new function get_call_wd() can be used from within a test file. It returns the working directory that was active when the test sequence was invoked (e.g. by test_all()). Useful because tinytest temporarily and safely switches working directory to the location of the test file (and returns afterwards).

The condition-catching functions expect_error, expect_warning, and expect_message gain a class argument, that can be used to check whether a signaling condition inherits from a certain class.

Updates, fixes

  • Argument ‘tol’ now renamed ‘tolerance’. Also removed internal reliance on
    partial argument matching (Thanks to Michel Lang).
  • Updated documentation on how to extend tinytest with new recommendation.
  • Using tinytest vignette gains section on testing internal functions.
  • Breaking: function ‘expect_message’ no longer intercepts messages sent
    to stdout (e.g. via ‘print’ or ‘cat’), but only messages send as a ‘message’
    condition (Thanks to Michel Lang for pointing this out).
  • Fix: ‘test_package’ would return NULL when called interactively and the package
    contained a failing test.

Thanks

I’m truly grateful for the contributions by people who have helped me improve tinytest by providing suggestions, bug reports, and comments. For this release, I am especially grateful to Michel Lang, Maja Zaloznik and Jon Clayden.

To leave a comment for the author, please follow the link and comment on their blog: R – Mark van der Loo.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)