covr shows 0% of coverage while all tests with testthat pass
Asked Answered
S

1

11

I have built a package with unit tests for most of the functions. The package has a standard structure:

package:
  - R/
    - file1.R
    - file2.R
    - ...
  - tests/
    - testthat/
      - tests_for_file1.R
      - tests_for_file2.R
      - ...
  - ...

Calling a function devtools::check() in R console gives me no errors

R CMD check results
0 errors | 1 warning  | 1 note

Calling a function devtools::test() is also successful

OK:       72
Failed:   0
Warnings: 0
Skipped:  0

However covr::package_coverage() give me this result

package Coverage: 0.00%
R/file1.R: 0.00%
R/file2.R: 0.00%
...

Why?

Skipjack answered 15/10, 2018 at 10:24 Comment(2)
I have had something like this happen as well. Have you looked at the results from covr::report()? If so, was it any different?Hanshaw
Also, is your package source code publicly available, for example in a GitHub repo?Hanshaw
S
12

I found the answer to the problem here

I was missing package/tests/testthat.R file, which can be set up with usethis::use_testthat() and usethis::use_test(). It helped me.

Skipjack answered 19/10, 2018 at 10:42 Comment(3)
I already have this file in place, but am still facing this issue. Did anyone else face this issue?Rotogravure
Thanks! I had my path as package/tests/testthat/testthat.R and it didn't work. Changing it to package/tests/testthat.R worked.Phenylamine
In my case, I had some non-RData data in the data folder, so devtools::check() was giving an error. After putting them in the inst folder, devtools::check() went well, and the coverage changed when running devtools::test_coverage_active_file()Hexagram

© 2022 - 2024 — McMap. All rights reserved.