rstudio / shinytest2

https://rstudio.github.io/shinytest2/
Other
104 stars 18 forks source link

How to use {shinytest2} in tandem with {mockery}? #301

Open daattali opened 1 year ago

daattali commented 1 year ago

The {mockery} package prvoides a way to stub out functions for testing.

Suppose I have an app that I want to test with {shinytest2}, and one of the function calls inside the app's server takes a long time so I'd like to stub it out for a different function.

For example:

library(shiny)

ui <- fluidPage(
  numericInput("num", "number for analysis", 5),
  textOutput("result")
)

server <- function(input, output, session) {
  result <- reactive({
    some_heavy_analysis_function(input$num)
  })
  output$result <- renderText({
    result()
  })
}

shinyApp(ui, server)

You can imagine some_heavy_analysis_function() is a function defined in my package that takes a long time, but when testing the app with {shinytest2} I will want to replace stub it out for a constant-time function.

schloerke commented 1 year ago

Won't be possible until testthat file loading is implemented