Xml SoapUI:在断言通过或失败时自定义断言日志文本

Xml SoapUI:在断言通过或失败时自定义断言日志文本,xml,groovy,soapui,assertions,Xml,Groovy,Soapui,Assertions,我有一个脚本断言,它将XML响应中的值a与值B、C和D进行比较。如果值a等于值B、C或D中的任何一个,那么断言将通过,否则它将失败 // get the xml response def response = messageExchange.getResponseContent() // parse it

我有一个脚本断言,它将XML响应中的值a与值B、C和D进行比较。如果值a等于值B、C或D中的任何一个,那么断言将通过,否则它将失败

// get the xml response                                             
def response = messageExchange.getResponseContent()                                                 
// parse it                                             
def xml = new XmlSlurper().parseText(response)                                              
// find your node by name                                               
def node = xml.'**'.find { it.name() == 'total-premium' }                                               
// assert                                               
(assert node.toString().matches("(36.476|38.395|40.315)\\d*"))
对于传递的断言,我在日志中得到以下字符串:

Step 1 [TestStep_0001] OK: took 2296 ms
 -> [Script Assertion] assert node.toString().matches((36.476|38.395|40.315)\\d*")           |    |          |           |    37.6033658 false           37.6033658
我在日志中得到了一个失败的断言:

Step 1 [TestStep_0001] OK: took 2296 ms
 -> [Script Assertion] assert node.toString().matches((36.476|38.395|40.315)\\d*")           |    |          |           |    37.6033658 false           37.6033658
正如您所看到的,它有点混乱,我正在尝试整理测试套件日志


有没有办法在日志中设置自定义响应

我不确定这是否是您想要的,但您可以自定义
断言
将字符串作为消息传递,当
断言
失败时,将显示或记录该消息

比如:

assert node.toString().matches("(36.476|38.395|40.315)\\d*"), 'Assert fail custom message'
这样,当您执行TestCase时,如果日志中的
断言失败,您将看到以下内容:

[Script Assertion] Assert fail custom message. Expression: node.toString().matches((36.476|38.395|40.315)\d*)
根据评论更新:

您没有删除
assert
消息的一部分的方法,如果如前一个解决方案所示,使用
assert表达式“custom fail message”
删除自定义消息对于您的情况是不够的(因为您似乎还想删除结果消息中的
表达式:
部分);完全定制消息的一个可能解决方案是捕获
assert
引发的
java.lang.AssertionError
异常,并在日志中打印所需消息:

def node = 3
try {
    assert node.toString().matches("(36.476|38.395|40.315)\\d*")
} catch (AssertionError e) {
    log.info "Your custom message without expression"
}

是否仍有隐藏表达式部分的方法?