首页 > 解决方案 > 如何使用 shinytest 记录或跟踪?

问题描述

我希望能够看到reactive({...})我的代码部分内部发生了什么。我认为使用 shinytest 可能是一种执行我的应用程序部分的方法,这些部分使用Shiny Modules和了解callModule.

我在我的代码中尝试了以下内容来记录/跟踪/打印。

print("hello1")
message("hello2")
cat(file=stderr(), "hello3")
logging::loginfo("hello4")

运行测试

library(shinytest)
testApp("/home/eddy/rwork/filters", "mytest")
viewTestDiff("/home/eddy/rwork/filters", interactive = FALSE)

输出:

Rscript runtest.R
Running mytest.R 
==== Comparing mytest... No changes.
==== mytest ====
No differences between expected and current results

如何在测试运行中添加一些跟踪输出?

标签: rshinyrstudio

解决方案


我不认为现在有一种非常方便的方法可以在 shinytest 中查看应用程序输出,但是 ShinyDriver 对象上有这个方法:

app$getDebugLog()查询一个或多个调试日志:shiny_console,browsershinytest.

https://rstudio.github.io/shinytest/reference/ShinyDriver.html

您可以将此shiny_console选项与在单个测试中打印应用程序输出的选项一起使用,例如:

# mytest.R

app <- ShinyDriver$new()

...

log <- app$getDebugLog("shiny_console")
print(log)

推荐阅读