在R包的/src文件夹中进行代码的单元测试? [英] Unit tests for code in the /src folder of an R package?
问题描述
我正在为R程序包做出贡献,该程序包广泛使用C代码进行计算.
I am contributing to an R package that makes extensive use of C code for computation.
我们已经开始使用 testthat 包为R函数编写测试,并将按照此处的说明在inst/tests
中进行测试.
We have started writing tests for R functions using the testthat package, placing the tests in inst/tests
following instructions here.
testthat软件包是否适合直接测试C函数(例如那些没有R接口的函数)?还是我们找到一个单独的C测试包?如果是这样,1)这些测试应该去哪里,2)如何在R CMD check
期间运行它们,以及3)在这种情况下,任何C测试包是否特别合适?
Is the testthat package appropriate for testing C functions directly (e.g. those without R interfaces)? Or do we find a separate C testing package? If so, 1) where should these tests go, 2) how do I get them to run during R CMD check
, and 3) is any C testing package particularly appropriate in this context?
推荐答案
我发现这个问题有些困惑:
I find the question a little confused:
-
您要么认为您的C代码都支持可以在R上进行测试的高级R函数(好像您已经这样做了)
Either you consider your C code to be in support of higher-level R functions that you can test at the R (as you seem to have done)
或者您认为您的C代码更独立,在这种情况下,您可以使用一个不计其数的C单元测试框架.
Or you consider your C code to be more standalone, in which case you could use one of a bazillion unit testing frameworks for C.
许多使用Rcpp的软件包还通过RUnit或testthat使用了大量的单元测试.您可以看一下.我通常在R函数级别进行测试,这通常意味着对基础C ++函数进行了测试.
Many of the packages using Rcpp also use extensive unit testing, either via RUnit, or via testthat. You could look at that. I generally test at the R function level, which often implies a test of the underlying C++ function.
这篇关于在R包的/src文件夹中进行代码的单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!