【发布时间】:2017-03-17 18:51:05
【问题描述】:
我正在使用 groovy 运行测试用例并断言数据。我想将每条失败的消息打印到html junit generate report。
示例代码
import groovy.json.JsonSlurper
def ResponseMessage = messageExchange.response.responseContent
def jsonString = new JsonSlurper().parseText(ResponseMessage)
assert !(jsonString.isEmpty())
assert jsonString.code == 200
assert jsonString.status == "success"
def accountInfo = jsonString.data
assert !(accountInfo.isEmpty())
def inc=0
//CHECKING LANGUAGES IN RESPONSE
if(accountInfo.languages.id!=null)
{
log.info("Language added successfully")
}
else
{
log.info("Language NOT added.") //want to display this in html report
inc++
}
if(accountInfo.educations!=null)
{
log.info("Educations added successfully")
}
else
{
log.info("Educations NOT added.") //want to display this in html report
inc++
}
assert inc<=0,"API unable to return all parameters, Please check logs"
场景
我在这里做的是,如果测试条件不匹配并转到 ELSE,我将变量 inc 增加 1。所以最后如果失败如果inc>0,我的测试。
举报
在 junit 样式的 html 生成报告中,如果测试失败,它只显示一条名为 API unable to return all parameters, Please check logs 的消息
但我想要的是将每个 IF 条件消息显示到 HTML 报告中,如果任何条件进入 ELSE 部分。
【问题讨论】: