如何将所有断言失败消息打印到 SoapUI 的 HTML 报告中
How to print all assertion failure messages into HTML report of SoapUI
我正在 运行 测试用例并使用 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部分。
一些建议:
- 断言在第一次失败时停止,只有这个失败消息是 junit 报告的一部分。
- 话虽如此,用户将不知道当前响应是否还有进一步的验证失败。
- 属于
if..else
的邮件不属于 junit report
- 为了实现这一点,需要收集所有这些消息并最终显示收集到的错误消息。
- 下面的解决方案使用变量
messages
并附加每个失败,以便在最后显示它们。这样,如果 OP 要求这样做,所有失败都可以显示在报告中。
除了 assert
语句
之外,用户还可以使用以下语句在报告中显示消息
if (messages) throw new Error(messages.toString())
脚本断言
import groovy.json.JsonSlurper
//check if the response is empty
assert context.response, 'Response is empty or null'
def jsonString = new JsonSlurper().parseText(context.response)
def messages = new StringBuffer()
jsonString.code == 200 ?: messages.append("Code does not match: actual[${jsonString.code}], expected[200]\n")
jsonString.status == "success" ?: messages.append("Status does not match: actual[${jsonString.status}], expected[success]\n")
def accountInfo = jsonString.data
accountInfo ?: messages.append('AccountInfo is empty or null\n')
def inc=0
//CHECKING LANGUAGES IN RESPONSE
if(accountInfo.languages.id) {
log.info('Language added successfully')
} else {
log.error('Language NOT added.') //want to display this in html report
messages.append('Language not added.\n')
inc++
}
if(accountInfo.educations) {
log.info('Educations added successfully')
} else {
log.error('Educations NOT added.') //want to display this in html report
messages.append('Educations NOT added.\n')
inc++
}
//inc<=0 ?: messages.append('API unable to return all parameters, Please check logs.')
//if(messages.toString()) throw new Error(messages.toString())
assert inc<=0, messages.append('API unable to return all parameters, Please check logs.').toString()
我正在 运行 测试用例并使用 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部分。
一些建议:
- 断言在第一次失败时停止,只有这个失败消息是 junit 报告的一部分。
- 话虽如此,用户将不知道当前响应是否还有进一步的验证失败。
- 属于
if..else
的邮件不属于junit report
- 为了实现这一点,需要收集所有这些消息并最终显示收集到的错误消息。
- 下面的解决方案使用变量
messages
并附加每个失败,以便在最后显示它们。这样,如果 OP 要求这样做,所有失败都可以显示在报告中。 除了
之外,用户还可以使用以下语句在报告中显示消息assert
语句if (messages) throw new Error(messages.toString())
脚本断言
import groovy.json.JsonSlurper
//check if the response is empty
assert context.response, 'Response is empty or null'
def jsonString = new JsonSlurper().parseText(context.response)
def messages = new StringBuffer()
jsonString.code == 200 ?: messages.append("Code does not match: actual[${jsonString.code}], expected[200]\n")
jsonString.status == "success" ?: messages.append("Status does not match: actual[${jsonString.status}], expected[success]\n")
def accountInfo = jsonString.data
accountInfo ?: messages.append('AccountInfo is empty or null\n')
def inc=0
//CHECKING LANGUAGES IN RESPONSE
if(accountInfo.languages.id) {
log.info('Language added successfully')
} else {
log.error('Language NOT added.') //want to display this in html report
messages.append('Language not added.\n')
inc++
}
if(accountInfo.educations) {
log.info('Educations added successfully')
} else {
log.error('Educations NOT added.') //want to display this in html report
messages.append('Educations NOT added.\n')
inc++
}
//inc<=0 ?: messages.append('API unable to return all parameters, Please check logs.')
//if(messages.toString()) throw new Error(messages.toString())
assert inc<=0, messages.append('API unable to return all parameters, Please check logs.').toString()