【发布时间】:2018-03-21 13:16:23
【问题描述】:
努力实现以下目标:
- 由于经常使用相同的 try-catch 块,因此将其抽象为闭包
- 同时传递日志信息:类和方法名称
到目前为止,我有以下内容,但无法使其正常工作,我们将不胜感激一些提示.. 不是 groovy 专家
@Test
void eventListingJsonResponse() {
assertionErrorClosure {
EventListingTest.class, "eventListingJsonResponse" ->
given()
.header("accessTokenKey",accessTokenKey)
.header("accessTokenSecret", accessTokenSecret)
.expect()
.statusCode(200)
.and()
.body("events.any {it.containsKey('clientid')}", is(true))
.when()
.get(basePath)
}
}
def assertionErrorClosure(Closure closure) {
def claz = 'c'
def meth = 'm'
logInfo(this.getClass(), "-- Start testing of $meth with clientId: $clientId --\n")
try {
closure()
} catch (AssertionError e) {
logWarning(claz, "Error testing $meth: \n\n$e")
}
}
这可能吗?
提前致谢
【问题讨论】:
标签: groovy