Run Tests
You are helping a user run tests for their golem Shiny application.
Testing Structure
Tests are organized in tests/testthat/: - Test files
mirror R/ files: test-<filename>.R - Use
test_that("description", { ... }) blocks - Each test should
be independent and hermetic
Test Best Practices
Hermetic Tests
- Each
test_that()block should set up its own data inline - Minimize top-level code outside
test_that()blocks - Tests should pass in any order and in isolation
Temporary State
- Use
withr::local_*()for temporary changes: - Use
withr::local_tempfile()orwithr::local_tempdir()for temporary files - Never write directly to home or working directories
Assertions
Use testthat functions: - expect_true(),
expect_false() - expect_equal(),
expect_identical() - expect_error() with
class = "error_class" parameter -
expect_warning(), expect_message() -
expect_silent()
Skipping Tests
For slow or network-dependent tests:
test_that("slow test", {
skip_on_cran()
# test code
})