我在一家采用非正统方式组织文件夹的公司工作,我希望能够告诉testthat
它应该在哪个文件夹中查找我的功能。例如,使用以下文件结构:
.
├── data
│ ├── input
│ └── output
└── src
├── Ex
├── Py
│ └── tests
└── R
└── tests
我想告诉testthat
,我所有的测试都位于./src/R/tests
中,我的代码位于./src/R/
中。有没有一种方法可以指定这些路径,以便包知道在哪里查找文件?
您可以source
测试和使用test_dir
:的函数
library(testthat)
path <- 'src/R'
files <- file.path(path,list.files(path,pattern='\.R$'))
lapply(files,source)
testresults <- test_dir('src/R/tests/testthat',
reporter = "list",
env = test_env(),
start_end_reporter = TRUE,
load_helpers = TRUE,
stop_on_failure = FALSE)