有没有办法递归地进行测试?

Vro*_*pal 1 r testthat

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

.
+--Projroot
+---- R
|     -- routine1.R
|     -- routine2.R
+---- tests
      -- test_routine1.R
      -- test_routine2.R
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

刚刚运行devtools::test()不会捕获test_*.R内部目录中的文件.

有没有办法testthat递归搜索?

Col*_*FAY 5

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)
Run Code Online (Sandbox Code Playgroud)

  • 嗨,这确实不是一个干净的解决方案,而是一种绕过test的本地行为的方法;) (2认同)