残りのワークフロー用にいくつかのフォルダーを設定する関数があります
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()
テストを書き直して機能させる方法を提供したり、存在チェックの期待を提供したりできる人はいますか?