Convert RUnit tests to testthat tests.
To install, you first need the devtools package.
install.packages("devtools")
Then you can install the runittotestthat package using
library(devtools)
install_github("richierocks/runittotestthat")
There are three functions of interest:
-
convert_testconverts an individualRUnittest to a call to atestthattest.test_truth <- function() { x <- all(runif(10) > 0) checkTrue(x) } convert_test(test_truth) ## test_that("test_truth", { ## x <- all(runif(10) > 0) ## expect_true(x) ## }) test_equality <- function() { x <- sqrt(1:5) expected <- c(1, 4, 9, 16, 25) checkEquals(expected, x ^ 4) } convert_test(test_equality) ## test_that("test_equality", { ## x <- sqrt(1:5) ## expected <- c(1, 4, 9, 16, 25) ## expect_equal(x^4, expected) ## }) test_error <- function() { checkException("1" + "2") } convert_test(test_error) ## test_that("test_error", { ## expect_error("1" + "2") ## }) -
convert_test_filesources all the tests in a file, converts each one, then outputs them to a file (or file connection;stdoutby default). -
convert_package_teststakes a string naming a package, or adevtools::packageobject and loops over the files ininst/tests(or wherever you specify), converting the tests, and outputting to files orstdout.