rr-packagetestthatcovr

Location of tests file in an R package


If I have tests/testhat/testhat.R, devtools::test() finds it and runs it, but covr:package_coverage() and R CMD check does not find it.

If I have it as tests/testhat.R, devtools::test() doesn't find it but covr:package_coverage() and R CMD check does.

What's the best way to do this?

R 4.0.0; testthat 2.3.2; covr 3.5.0


Solution

  • Your directory structure of the test folder should look like this:

    .
    ├── testthat
    │   ├── test-1.R
    │   ├── test-2.R
    │   ├── test-3.R
    │   ├── test-4.R
    │   └── test-5.R
    └── testthat.R
    

    And testthat.R contains

    library(testthat)
    library(mypackage)
    
    test_check("mypackage")
    

    This works with R CMD check, covr and devtools::check().