R 有没有一种方法可以让测试递归地进行搜索?

R 有没有一种方法可以让测试递归地进行搜索?,r,testthat,R,Testthat,当我的R包目录结构在tests文件夹中直接包含R文件时 . +--Projroot +---- R | -- routine1.R | -- routine2.R +---- tests -- test_routine1.R -- test_routine2.R testthat捕获test.*.R文件,但是当测试本身依赖于大量文件时,拥有测试子目录会更干净 . +--Projroot +---- R | -- routine1.R |

当我的R包目录结构在tests文件夹中直接包含R文件时

.
+--Projroot
+---- R
|     -- routine1.R
|     -- routine2.R
+---- tests
      -- test_routine1.R
      -- test_routine2.R
testthat
捕获
test.*.R
文件,但是当测试本身依赖于大量文件时,拥有测试子目录会更干净

.
+--Projroot
+---- R
|     -- routine1.R
|     -- routine2.R
+---- tests
      |
      +---- test_routine1
      |     -- test_routine1.R
      |     -- help_file11
      |     -- help_file12
      +---- test_routine2
            -- test_routine2.R
            -- help_file21
            -- help_file22
仅运行
devtools::test()
不会捕获内部目录中的
test.*.R
文件

有没有一种方法可以使
testthat
递归搜索?

devtools::test()
调用
testthat::test\u dir

testthat::test_dir
查找要使用的文件
testthat:::find_test_scripts
。而且该函数不会递归地查看文件夹内部,因此本机不,
test无法在内部目录中进行测试

您仍然可以这样运行测试,不过:

my_test <- list.files(path = "tests", pattern = "test_|help_", recursive = TRUE, full.names = TRUE)
lapply(my_test, test_file)

my_test收集“test_uu.R”文件,无论它们在“tests”中的任何位置,并将它们传递给testthat。那是个好主意。但是testthat在
tests/testthat
目录中方便地运行它的断言,因此如果您有一个
加载(file=“x.rda”)
(因为您已经运行了,例如,
x=c(5,7)
,然后是
保存(x,file=“x.rda”)
,则会找到“x.rda”文件。现在似乎需要编写一个选项来插入路径以定位每个给定文件。这没什么大不了的,但我想知道你是否建议一个真正干净的解决方案。嗨,这确实不是一个干净的解决方案,而是一种绕过testthat的原生行为的方法;)这难道不妨碍测试的适当模块化吗?