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_dir

testthat::test_dir找到使用testthat:::find_test_scripts测试的文件。而且此功能在文件夹中不会递归,因此本地否,testthat无法在内部目录内进行测试。

但是,您仍然可以这样运行测试:

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

最新更新