尝试实现以下目标:
到目前为止我有以下内容但是无法让它工作,一些提示会非常感激..不是一个时髦的专家
@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")
}
}
这可能吗?
提前致谢
答案 0 :(得分:1)
你几乎就在那里,你必须将闭包参数和闭包本身分别传递给assertionErrorClosure
函数,如下所示:
assertionErrorClosure(this.class, "eventListingJsonResponse") {
clazz, methodName ->
print "hello world from class: ${clazz} and method: ${methodName}"
//your test code here
}
def assertionErrorClosure(Class clazz, String methodName, Closure closure) {
print("" + clazz + "-- Start testing of $methodName --\n")
try {
closure(clazz, methodName)
} catch (AssertionError e) {
logWarning(claz, "Error testing $methodName: \n\n$e")
}
}
您可以将print()
替换为记录器,将this.class
替换为EventListingTest.class
。