gpt4 book ai didi

r - 一次测试它和 covr

转载 作者:行者123 更新时间:2023-12-05 05:16:50 25 4
gpt4 key购买 nike

我想使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com