Learn R Programming

runittotestthat

Convert RUnit tests to testthat tests.

Installation

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")

Converting tests

There are three functions of interest:

  1. convert_test converts an individual RUnit test to a call to a testthat

test.

```{r}
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")
## })
```
  1. convert_test_file sources all the tests in a file, converts each one, then

outputs them to a file (or file connection; stdout by default).

  1. convert_package_tests takes a string naming a package, or a

devtools::package object and loops over the files in inst/tests (or wherever you specify), converting the tests, and outputting to files or stdout.

Copy Link

Version

Install

install.packages('runittotestthat')

Monthly Downloads

11

Version

0.0-2

License

Unlimited

Maintainer

Last Published

June 24th, 2015

Functions in runittotestthat (0.0-2)

convert_checkIdentical

Convert a checkIdentical call.
convert_repeat

Convert a repeat block.
convert_if

Convert an if block.
convert_brace

Convert a code block.
convert_package_tests

Convert a package worth of RUnit tests to testthat tests
get_filename

Get a quoted filename
convert_lines

Convert lines of RUnit code to testthat code
convert_line

Convert lines of RUnit code to testthat code
convert_checkTrue

Convert a checkTrue call.
convert_switch

Convert a switch block.
runittotestthat

Convert RUnit tests to testthat tests.
convert_for

Convert a for block.
convert_checkEqualsNumeric

Convert a checkEqualsNumeric call.
convert_checkEquals

Convert a checkEquals call.
convert_while

Convert a while block.
convert_test

Convert an RUnit test to a testthat test
convert_checkException

Convert a checkException call.
convert_test_file

Convert a file worth of RUnit tests to testthat tests