RUnit 的长期用户最近切换到tinytest 的警告,您正在寻找的功能已经存在于tinytest 中。我认为有人已经或可能在某个时候为testthat 构建了一个并行测试运行程序,但在“此时此地”中,我们确实有tinytest 具有非常好的行为、良好的文档和从RUnit 转换的线索或testthat。
我最喜欢tinytest 的功能是在包中默认安装测试、缺少其他依赖项和并行运行器。
还有一个警告:我更喜欢这种方式的命令行,而不是 R 提示符,因为可能总会有某种形式的副作用。所以我在littler 中添加了一个小测试运行器wrappre tt.r:
edd@rob:~$ tt.r -h
Usage: tt.r [-h] [-x] [-a] [-b] [-d] [-f] [-n NCPUS] [-p] [-s] [-z] [ARG...]
-a --all use test_all mode [default: FALSE]
-b --build use build-install-test mode [default: FALSE]
-d --directory use directory mode [default: FALSE]
-f --file use file mode [default: FALSE]
-n --ncpus NCPUS use 'ncpus' in parallel [default: getOption]
-p --package use package mode [default: FALSE]
-s --silent use silent and do not print result [default: FALSE]
-z --effects suppress side effects [default: FALSE]
-h --help show this help text
-x --usage show help and short example usage
edd@rob:~$
(我应该在这里补充一点,感谢docopt,编写这样的包装器很容易。)
然后我们就这样做
edd@rob:~$ tt.r -n 4 -p anytime
starting worker pid=642068 on localhost:11092 at 17:11:25.636
starting worker pid=642067 on localhost:11092 at 17:11:25.654
starting worker pid=642065 on localhost:11092 at 17:11:25.687
starting worker pid=642066 on localhost:11092 at 17:11:25.689
Running test_gh_issue_12.R............ 2 tests OK
Running test_gh_issue_56.R............ 7 tests OK
Running test_gh_issue_33.R............ 2 tests OK
Running test_all_formats.R............ 0 tests ris or Windows or Release
Running test_assertions.R............. 2 tests OK
Running test_calc_unique.R............ 4 tests OK
Running test_gh_issue_100.R........... 2 tests OK
Running test_simple.R................. 34 tests OK
Running test_utilities.R.............. 2 tests OK
Running test_bulk.R................... 2328 tests OK
[1] "All ok, 2383 results"
edd@rob:~$
你看到有一点输出被吞没了。
您当然也可以从 R 手动运行它:
R> tinytest::test_package("anytime", ncpu=4)
starting worker pid=651865 on localhost:11762 at 17:14:45.970
starting worker pid=651864 on localhost:11762 at 17:14:45.980
starting worker pid=651863 on localhost:11762 at 17:14:45.980
starting worker pid=651862 on localhost:11762 at 17:14:45.984
Running test_gh_issue_12.R............ 2 tests
Exited 'test_all_formats.R' at line 24. Skipping Solaris or Windows or ReleaseOK
Running test_all_formats.R............ 0 tests
Running test_gh_issue_56.R............ 7 tests OK
Running test_assertions.R............. 2 tests OK
Running test_gh_issue_33.R............ 2 tests OK
Running test_calc_unique.R............ 4 tests OK
Running test_gh_issue_100.R........... 2 tests OK
Running test_simple.R................. 34 tests OK
Running test_utilities.R.............. 2 tests OK
Running test_bulk.R................... 2328 tests OK
[1] "All ok, 2383 results"
R>
文件、目录、构建+安装+测试循环等还有其他运行程序。嘿,如果在这一切之后你仍然不喜欢它,马克会把你的钱还给你:)
PS 在这里,例如在Rcpp 中,我有一些测试“变暗”,因为它们会产生大量的 cmdline 噪音,因此只有在设置了 opt-in var 时才会在包测试中发生。因此,上面的几个“零测试运行”。这是我的设置,不是tinytest 问题。