“UseMethod(“xml_add_child”) 中的错误“test_dir 不起作用

alb*_*lar 2 testing r testthat

当我尝试在 test_dir 函数中定义路径时,它显示错误:

Error in UseMethod("xml_add_child") : no applicable method for 'xml_add_child' applied to an object of class "NULL"
Run Code Online (Sandbox Code Playgroud)

我的 testthat.R 文件有以下几行:

library(testthat)
library(package)

options(testthat.junit.output_file = "test-out.xml")
test_dir("tests/testthat/0_utils/", reporter = 'junit')
test_package("package")
Run Code Online (Sandbox Code Playgroud)

我的测试位于“tests/testthat/0_utils”文件夹中。我怎么解决这个问题?

alb*_*lar 5

要解决此问题,您必须确保所有测试都以context()第一行中的 a 开头。