testthat
Basic Setup
Solution Code
add <- function(a, b) {
a + b
}
add <- function(a, b) {
a + b
}
Test Fixture
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 Code
Preloaded
f <- function(a, b) { a + b }
f <- function(a, b) { a + b }
Solution Code
source("setup.R")
add <- f
source("setup.R")
add <- f
Test Fixture
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)
})