tests/testthat/test-examples.R

test_that("test_examples works with installed packages", {
  local_edition(2)

  local_mocked_bindings(test_rd = identity)
  expect_true(length(test_examples()) > 1)
})

test_that("test_examples fails if no examples", {
  withr::local_envvar(TESTTHAT_PKG = "")
  expect_error(test_examples("asdf"), "Could not find examples")
})

Try the testthat package in your browser

Any scripts or data that you put into this service are public.

testthat documentation built on April 4, 2025, 1:08 a.m.