0
我會設置一些文件夾我的工作流如何使用testthat R中
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」
由於我正在檢查文件夾的存在,我不確定如何去測試這個包含函數analyzeFolderCreation的expectation格式。
我在dev_mode()
運行,並有明確的執行測試文件test_file()
是任何人都能夠提供重寫測試工作,或提供生存確認預期的一種方式?
對不起,但我沒有看到'test_that('是什麼?你在哪裏定義了代碼? – 2013-04-22 15:46:57
@ SimonO101:OP未能清楚地表明他正在使用Hadley的testthat包 – 2013-04-22 15:52:29
@DWin謝謝!我發現'RUnit',但找不到相應的函數。 – 2013-04-22 15:55:41