【问题标题】:How to run a package's testthat tests如何运行测试包的测试
【发布时间】:2019-02-10 00:24:19
【问题描述】:

对于给定的已安装包,我如何运行它的 testthat 测试?我不是已安装软件包的开发人员,我是用户。我只想运行它的测试套件来确认它的测试在我的环境中通过。我试过test_checktest_package 但我看到了错误。

更具体地说,我知道它的测试套件失败了,我想在交互式 R 会话中运行测试,以便调试它。

> require(eplusr)    # choice of package unimportant. Any using testthat will do.
Loading required package: eplusr
> require(testthat)
Loading required package: testthat
> test_check("eplusr")
Error in test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure,  : 
  No matching test file in dir
> test_package("eplusr")
Error: No tests found for eplusr


> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] testthat_2.0.0 eplusr_0.9.1  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18      magrittr_1.5      units_0.6-0       hms_0.4.2         progress_1.2.0    uuid_0.1-2        bit_1.1-14        debugme_1.1.0     R6_2.2.2          rlang_0.2.2      
[11] stringr_1.3.1     blob_1.1.1        tools_3.5.1       data.table_1.11.5 cli_1.0.0         DBI_1.0.0         withr_2.1.2       bit64_0.9-7       assertthat_0.2.0  digest_0.6.16    
[21] tibble_1.4.2      crayon_1.3.4      processx_3.2.0    readr_1.1.1       callr_3.0.0       later_0.7.4       base64enc_0.1-3   ps_1.1.0          fasttime_1.0-2    memoise_1.1.0    
[31] RSQLite_2.1.1     stringi_1.2.4     pillar_1.3.0      compiler_3.5.1    prettyunits_1.0.2 lubridate_1.7.4   pkgconfig_2.0.2  

【问题讨论】:

    标签: r testthat


    【解决方案1】:

    你不能(除非你重新安装覆盖默认行为,如 Brodie 的回答所示)。

    这是一个设计缺陷^Hchoice。 testthat 尽其所能,决定默认安装测试,方法是强制放置在tests/ 目录中。 R 提供了一个覆盖它的选项(如图所示),该选项通常未打开。于是就进退两难了。

    当然,RUnitinst/ 以下的测试中一直都是正确的。所以如果一个包使用RUnit,你可以在安装后运行它的测试。无需重新安装。

    编辑: 1 1/2 年后,我们中的许多人现在使用去年推出的 tinytest 包。除其他优点外,还允许非常容易测试已安装的包。

    【讨论】:

      【解决方案2】:

      R 默认不安装测试。为此请尝试:

      install.packages('eplusr', INSTALL_opts="--install-tests", type='source')
      

      然后,要么:

      testthat::test_package('eplusr')
      

      或者使用内置的testInstalledPackage:

      tools::testInstalledPackage('eplusr')
      

      【讨论】:

        猜你喜欢
        • 2016-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-19
        • 2019-02-17
        • 1970-01-01
        • 2012-04-06
        • 2013-03-30
        相关资源
        最近更新 更多