Self-contained tests

Each test_that() test has its own execution environment:

  • An R object you create inside a test does not exist after the test exits.
exists("thingy")
#> [1] FALSE

test_that("thingy exists", {
  thingy <- "thingy"
  expect_true(exists(thingy))
})
#> Test passed

exists("thingy")
#> [1] FALSE