【发布时间】:2020-01-07 14:21:58
【问题描述】:
我想使用“testthat”将测试添加到我的包中。
这是我的测试文件:
library(RBaseX)
test_that("Credentials are accepted", {
skip_unless_socket_available()
expect_error(BasexClient$new("localhost", 1984L, username = "admin", password = "denied"), "Access denied")
Session <- BasexClient$new("localhost", 1984L, username = "admin", password = "admin")
expect_equal(class(Session)[[1]], "BasexClient")
})
skip_unless_socket_available 在单独的 helper.R 文件中定义:
skip_unless_socket_available <- function() {
tryCatch({
Socket <- socketConnection(host = "localhost", 1984,
open = "w+b", server = FALSE, blocking = TRUE, encoding = "utf-8")
close(Socket)
TRUE
}, error = function(e) {
skip(paste0("basexserver not available:\n'", conditionMessage(e), "'"))
})
}
当程序执行时,我得到这个输出:
Loading RBaseX
Testing RBaseX
✓ | OK F W S | Context
✓ | 2 | test_RbaseX [0.2 s]
⠹ | 2 1 | test_RbaseX
══ Results ═══════════════════════════════
Duration: 0.3 s
OK: 2
Failed: 1
Warnings: 0
Skipped: 0
无论我做什么,我仍然会失败 1 次。但是,这两个异常都得到了正确处理。
我应该如何处理这个失败?
本
在 test_RBaseX.R 中插入 3 个 contexts() 后,我现在得到以下输出:
Loading RBaseX
Testing RBaseX
✓ | OK F W S | Context
✓ | 2 | Access [0.1 s]
✓ | 2 | Create Session [0.1 s]
⠏ | 0 | Check setter/getter (and BasexClient$Execute())
✓ | 2 | Check setter/getter (and BasexClient$Execute())
⠏ | 0 | Intercept set/get is handled correctlyDatabase 'TestOpen' is niet gevonden.
Database 'TestOpen' is niet gevonden.
Database 'TestOpen' is niet gevonden.
✓ | 1 | Intercept set/get is handled correctly
⠙ | 1 1 | Intercept set/get is handled correctly
══ Results ════════════════════════════════════════════
Duration: 0.4 s
OK: 7
Failed: 1
Warnings: 0
Skipped: 0
所有测试都给出了预期的结果,但随后添加了 1 个失败。我仍然没有看到任何迹象。
这有帮助吗?
本
(顺便说一句,由于这些测试活动,我发现并修复了一些错误:-))
【问题讨论】: