我正在尝试添加一个JUnit报告器来测试。虽然我可以在内部包(https://github.com/hadley/testthat/pull/481)中执行此操作但我无法在单独的包(https://github.com/lbartnik/testthatJUnit)中通过相同的测试集。
我的主要问题是,如果我将JUnit记者代码拉到一个单独的包中,那么为记者设计并在testthat
中出现的测试就不会通过。我猜测那些测试中有一些东西可以“设置场景”来测试记者,但是我无法识别这个“东西”。
任何帮助都非常感激。
详细信息如下。
> library(devtools)
> test("testthatJUnit")
Loading testthatJUnit
Testing testthatJUnit
JUnitReporter:
DONE ==========================================================================
> test("testthat")
Loading testthat
unloadNamespace("testthat") not successful, probably because another loaded package depends on it.Forcing unload. If you encounter problems, please restart R.
Testing testthat
Bare expectations:
Colours: ..
compare.character: .................
compare.numeric: .....................
compare.time: .......
# ... lines cut ...
DONE ===========================================================================
> test("testthatJUnit")
Loading testthatJUnit
Testing testthatJUnit
JUnitReporter: .............
如果我修改测试以查看为什么第一个test("testthatJUnit")
是静音的,我会看到:
> test("testthatJUnit")
Loading testthatJUnit
Testing testthatJUnit
JUnitReporter: Bare: .1
Failed -------------------------------------------------------------------------
1. Error: Junit reporter regression (@test-reporter-junit.R#13) ----------------
attempt to apply non-function
1: test_dir("test_dir") at /mnt/storage-a/lukaszb/src/third-party/testthatJUnit/tests/testthat/test-reporter-junit.R:13
2: test_files(paths, reporter = reporter, env = env, ...)
3: with_reporter(reporter = current_reporter, results <- lapply(paths, test_file, env = env,
reporter = current_reporter, start_end_reporter = FALSE, load_helpers = FALSE))
4: force(code)
5: lapply(paths, test_file, env = env, reporter = current_reporter, start_end_reporter = FALSE,
load_helpers = FALSE)
6: FUN(X[[i]], ...)
7: with_reporter(reporter = reporter, start_end_reporter = start_end_reporter, {
lister$start_file(basename(path))
source_file(path, new.env(parent = env), chdir = TRUE)
end_context()
})
8: force(code)
9: source_file(path, new.env(parent = env), chdir = TRUE)
10: eval(exprs, env)
11: eval(expr, envir, enclos)
12: expect_that(1, equals(1)) at test_dir/test-bare-expectations.R:3
13: condition(object)
14: expect_equal(x, expected, ..., expected.label = label)
15: expect(comp$equal, sprintf("%s not equal to %s.\n%s", lab_act, lab_exp, comp$message),
info = info)
16: withRestarts(if (expectation_broken(exp)) {
stop(exp)
} else {
signalCondition(exp)
}, continue_test = function(e) NULL)
17: withOneRestart(expr, restarts[[1L]])
18: doWithOneRestart(return(expr), restart)
19: signalCondition(exp)
20: (function (e)
{
register_expectation(e, frame + 11, sys.nframe() - 6)
invokeRestart("continue_test")
})(structure(list(message = "1 not equal to 1.\nEqual\n", srcref = NULL), .Names = c("message",
"srcref"), class = c("expectation_success", "expectation", "condition")))
21: register_expectation(e, frame + 11, sys.nframe() - 6)
22: get_reporter()$add_result(context = get_reporter()$.context, test = test, result = e)
23: o_apply(self$reporters, "add_result", context = context, test = test, result = result)
24: lapply(objects, function(x) x[[method]](...))
25: FUN(X[[i]], ...)
26: x[[method]](...)
但如果我再次运行test("testthat")
test("testthatJUnit")
,一切都会恢复正常:
> test("testthatJUnit")
Loading testthatJUnit
Testing testthatJUnit
JUnitReporter: Bare: ..
Basic: .......
empty: 1
error: 2.3456.
failures: 7.8..
helper: .
skip: S
我的猜测是testthat
的测试中有一些东西为测试记者设置场景,但到目前为止我还无法识别它。有什么帮助吗?
答案 0 :(得分:1)
实际上,结果发现testthat
1.0.2中存在一个已在github
来源(https://github.com/hadley/testthat/commit/99c25fc4efefa012a36d8fc912210ba3452a978d)中修复的错误。使用此版本的testthat
我的包中的所有测试都没有错误。