繁体   English   中英

r testthat和covr在非包装库中使用

[英]r testthat and covr use in a non-package library

我希望能够在一个不是 r包的项目中使用testthatcovr 实际上不使用任何第三方服务。 只是一个普通的r源文件的集合

我正在努力找出这是否可能,如果是这样,关于如何设置它的说明已经完成。

我发现的假设你正在写一个r包。 我喜欢避免这种开销。

现有技术:

  1. https://www.rstudio.com/resources/webinars/covr-bringing-test-coverage-to-r/
  2. https://walczak.org/2017/06/how-to-add-code-coverage-codecov-to-your-r-package/

这应该没有问题。

第一 :我有一个代码的文件,应该测试名为code.R

f1 <- function(n, ...) {
    rnorm(n = n, ...)
}

第二 :然后我有一个名为tests.R测试文件:

source("code.R")

test_that("Random tests", {
    tmp1 <- f1(10)
    expect_type(tmp1, "double")
    expect_equal(length(tmp1), 10)
})

第三 :然后你可以像这样运行测试和覆盖:

library(testthat)
library(covr)

test_file("tests.R")

res <- file_coverage("code.R", "tests.R")
res
report(res)

多个文件应该没问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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