r - 一次测试它和 covr

标签 r testthat covr

我想使用 testthat 为一个包运行测试,并使用 covr 计算代码覆盖率。此外,testthat 的结果应保存为 JUnit XML 格式,covr 的结果应保存为 Cobertura 格式。

下面的代码可以解决这个问题(当 getwd() 是包的根目录时):

options("testthat.output_file" = "test-results.xml")
devtools::test(reporter = testthat::JunitReporter$new())

cov <- covr::package_coverage()
covr::to_cobertura(cov, "coverage.xml")

但是,测试执行了两次。一次使用 devtools::test,一次使用 covr::package_coverage

我的理解是 covr::package_coverage 执行测试,但它不会生成 test-results.xml

如标题所示,我希望通过一次测试套件的执行获得 test-results.xmlcoverage.xml

最佳答案

来自 covr 引用手册 ( https://cran.r-project.org/web/packages/covr/covr.pdf )

This function uses tools::testInstalledPackage() to run the code, if you would like to test your package in another way you can set type = "none" and pass the code to run as a character vector to the code parameter

covr::package_coverage(
    type = "none",
    code = "testthat::test_package(
'myPackage',
reporter = testthat::JunitReporter$new(file = 'test-results.xml')
)")

关于r - 一次测试它和 covr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50021412/

相关文章:

r - 国家代码包中是否有区分美洲的选项?

r - 如何在 R 中运行多元回归时缩短 broom 中的代码?

r - test_that 的多重期望

r - 如何在需要时使用 testthat 将消息和警告静音

r - 如何在 golem 框架 Shiny 包中测试模块?

r - covr 显示 0% 的覆盖率,而所有带有 testthat 的测试都通过了

在 Knitr 中调整观星台的大小

r - 为什么我的 ggplot 对象变得这么大?