简体   繁体   中英

auto_test gives reporter error in testthat

I'm trying to force myself to do more unit testing on some data analysis projects where I don't really want to develop a package. So, I've been playing with the testthat R package. I have a code folder and inside it is a src and a test folder. In the src folder I have the file add.R that has this function:

add <- function(x,y){
    x+y
}

In the test folder I have the file test-add.R that contains this:

library(testthat)

test_that("adding numbers", {
    expect_equal(add(2,3), 5)
    expect_equal(add(5,5), 10)
})

The following works fine...

> source('code/src/add.R')
> test_file('code/test/test-add.R')

But I'd like to be able to use the auto_test function since as the project grows source / test_file will get tedious. But when I try auto_test I get this...

> auto_test('code/src', 'code/test')
Error in find_reporter(reporter) : attempt to apply non-function

I'm sure I'm missing something simple, but what?

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.1 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] testthat_0.11.0.9000 knitr_1.12.3        

loaded via a namespace (and not attached):
[1] lazyeval_0.1.10      R6_2.1.2             tools_3.2.3         
[4] withr_1.0.1          memoise_1.0.0        crayon_1.3.1        
[7] digest_0.6.9         devtools_1.10.0.9000

It seems that this is a problem of testthat version 0.11.0.9000. If I install this version from github, I get the same error message as you do:

auto_test('code/src', 'code/test')
## Error in find_reporter(reporter) : attempt to apply non-function

But with version 0.11.0 that can be installed from CRAN, your example runs fine:

auto_test('code/src', 'code/test')
## ..
## DONE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM