Skip to main content

testthat

Basic Setup​

Solution​

add <- function(a, b) {
  a + b
}
add <- function(a, b) {
  a + b
}

Tests​

context("add")

test_that("should add numbers", {
  expect_equal(add(1, 2), 3)
})
context("add")

test_that("should add numbers", {
  expect_equal(add(1, 2), 3)
})

Using Preloaded​

Preloaded​

f <- function(a, b) { a + b }
f <- function(a, b) { a + b }

Solution​

source("setup.R")
add <- f
source("setup.R")
add <- f

Tests​

context("add")

test_that("addition using preloaded works", {
  expect_equal(add(1, 1), 2)
})
context("add")

test_that("addition using preloaded works", {
  expect_equal(add(1, 1), 2)
})