我应该在哪里将数据与testthat一起进行自动化测试? [英] Where should I put data for automated tests with testthat?

查看:79
本文介绍了我应该在哪里将数据与testthat一起进行自动化测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Hadley基于testthat的方法来自动测试我的包裹.

I am using Hadley's testthat-based approach for automated testing of my package.

使用这种方法,最适合放置测试数据文件(即仅由test/testthat中的测试脚本使用的文件而不是R/中的任何其他函数使用的文件)的地方?

With this approach, what is the most suitable place to put test data files that is files only used by the test scripts in tests/testthat), but not by any other functions in R/?

我目前的方法是将它们放在tests/testdata中,然后从此处放入read.table并带有相对路径,而不是system.file(以避免需要安装软件包来运行测试).

My current approach is to put them in tests/testdata, and then read.table from there with a relative path rather than with system.file (in order to avoid the need to install the package to run tests).

有标准的方法吗?

推荐答案

从本博克尔的评论中摘录:

Lifting from Ben Bolker's comments:

我使用inst/testdata然后 system.file("testdata",...,package="my_package")

I use inst/testdata and then system.file("testdata",...,package="my_package")

此方法的优点:

  • 您可以保持文件结构整洁,尤其是在您有许多数据文件和/或测试的情况下.
  • inst中安装文件的事实是长期的规范R惯例;与../testdata/some_file相比,system.file("testdata", "some_file")始终可以正常工作似乎更安全.在执行R CMD check时,我在使用相对文件路径方面遇到了糟糕的经验.
  • 与Sathish的答案不同,它不依赖于您的数据作为R代码存储".
  • You can keep your file structure neat, especially if you have many data files and/or tests.
  • The fact that files in inst are installed is long-standing canonical R practice; it seems safer that system.file("testdata", "some_file") will always work than that ../testdata/some_file will do. I've had bad experiences using relative file paths when doing R CMD check.
  • Unlike Sathish's answer, it doesn't depend on your data being "stored" as R code.

这篇关于我应该在哪里将数据与testthat一起进行自动化测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆