我有一个功能可以为我的其余工作流程设置一些文件夹
library(testthat)
analysisFolderCreation<-function(projectTitle=NULL,Dated=FALSE,destPath=getwd(),SETWD=FALSE){
stopifnot(length(projectTitle)>0,is.character(projectTitle),is.logical(Dated),is.logical(SETWD))
# scrub any characters that might cause trouble
projectTitle<-gsub("[[:space:]]|[[:punct:]]","",projectTitle)
rootFolder<-file.path(destPath,projectTitle)
executionFolder<-file.path(rootFolder,if (Dated) format(Sys.Date(),"%Y%m%d"))
subfolders<-c("rawdata","intermediates","reuse","log","scripts","results")
dir.create(path=executionFolder, recursive=TRUE)
sapply(file.path(executionFolder,subfolders),dir.create)
if(Setwd) setwd(executionFolder)
}
我正在尝试对其进行单元测试,并且我的错误测试工作正常:
test_that("analysisFolderCreation: Given incorrect inputs, error is thrown",
{
# scenario: No arguments provided
expect_that(analysisFolderCreation(),throws_error())
})
但是我对成功的测试,不要...
test_that("analysisFolderCreation: Given correct inputs the function performs correctly",
{
# scenario: One argument provided - new project name
analysisFolderCreation(projectTitle="unittest")
expect_that(file.exists(file.path(getwd(),"unittest","log")),
is_true())
}
错误
- 错误:analysisFolderCreation:给定正确的输入,函数正确执行---------------------------- ------------------------ 找不到函数“analysisFolderCreation”
当我检查文件夹的存在时,我不确定如何以期望格式进行测试,该格式实际上包含函数 analysisFolderCreation 。
我正在运行dev_mode()
并明确执行测试文件test_file()
是否有人能够提供一种重写测试以使其工作的方法,或提供存在检查期望?