java - 预期和实际未显示在控制台日志中 - Groovy Spock

标签 java groovy spock

当我使用 testResponse.code == 401 时,我可以从控制台日志中看到“预期”和“实际”。但是当我使用 checkResponseCode(testResponse, 401) 时,我得到以下结果:

 Condition not satisfied:

checkResponseCode(testResponse, 401)
|         |
false     testpackage.project1.hs.unittestspack.utils.TestClass@17d88132

如何修复 checkResponseCode() 方法,使其生成预期的和实际的结果?这是 checkResponseCode() 的实现:

 static def checkResponseCode(resp, code) {
     resp.code == code
}

这是我想要实现的日志:

Condition not satisfied:

testResponse.code == 401
|                |    |
|                500  false
testpackage.project1.hs.unittestspack.utils.TestClass@5b367418

Expected :401

Actual   :500

 <Click to see difference>

最佳答案

您可以在辅助方法中断言条件:

static void checkResponseCode( resp, code ) {
    assert resp.code == code
}

关于java - 预期和实际未显示在控制台日志中 - Groovy Spock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48150196/

相关文章:

java - 在 JUnit 5 中参数化类和测试

grails - WSClient Soap客户端在grails/groovy中

gradle - 将字符串列表传递给 gradle 任务属性而不使用括号

grails - 从Grails 2.0.3升级到2.2.1:服务器访问错误:连接被拒绝

java - 从 jar 文件提供静态文件

java - 从最高到最低排列数字

java - 如何在spock测试中模拟私有(private)方法的返回值

java - 如何让 Spock 项目在 Eclipse 中运行?

java - 使用 getIntent().getExtras().getString 时出现空指针异常

java - @Path注释: abstract resource in dropwizard