Skip to content

This is a helper method that wraps around testthat::test_dir() to test your Shiny application or Shiny runtime document. This is similar to how testthat::test_check() tests your R package but for your app.


  app_dir = missing_arg(),
  name = missing_arg(),
  check_setup = TRUE,
  reporter = testthat::get_reporter(),
  stop_on_failure = missing_arg()



The base directory for the Shiny application.

  • If app_dir is missing and test_app() is called within the ./tests/testthat.R file, the parent directory ("../") is used.

  • Otherwise, the default path of "." is used.


Parameters passed to testthat::test_dir()


Name to display in the middle of the test name. This value is only used when calling test_app() inside of testhat test. The final testing context will have the format of "{test_context} - {name} - {app_test_context}".


If TRUE, the app will be checked for the presence of ./tests/testthat/setup-shinytest2.R. This file must contain a call to load_app_env().


Reporter to pass through to testthat::test_dir().


If missing, the default value of TRUE will be used. However, if missing and currently testing, FALSE will be used to seamlessly integrate the app reporter to reporter.


Example usage:

## Interactive usage
# Test Shiny app in current working directory

# Test Shiny app in another directory
path_to_app <- "path/to/app"

## File: ./tests/testthat.R
# Will find Shiny app in "../"

## File: ./tests/testthat/test-shinytest2.R
# Test a shiny application within your own {testthat} code
test_that("Testing a Shiny app in a package", {

Uploading files

When testing an application, all non-temp files that are uploaded should be located in the ./tests/testthat directory. This allows for tests to be more portable and self contained.

When recording a test with record_test(), for every uploaded file that is located outside of ./tests/testthat, a warning will be thrown. Once the file path has be fixed, you may remove the warning statement.

Different ways to test

test_app() is an opinionated testing function that will only execute testthat tests in the ./tests/testthat folder. If (for some rare reason) you have other non-testthat tests to execute, you can call shiny::runTests(). This method will generically run all test runners and their associated tests.

# Execute a single Shiny app's {testthat} file such as `./tests/testthat/test-shinytest2.R`
test_app(filter = "shinytest2")

# Execute all {testthat} tests

# Execute all tests for all test runners

See also