简体   繁体   中英

Groovy script assertion behaving strange

I have a test case where I have defined some custom properties for just performing an addition operation. Now I want to assert that the result is actually equal to the sum of both inputs. I wrote a groovy script for it to validate and log the two inputs and did a comparison check.

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( messageExchange.responseContent )
holder.namespaces["ns"] = "http://tempuri.org/"
def conversionRate = holder.getNodeValue("//ns:AdditionResult")
log.info messageExchange.modelItem.testStep.testCase.getPropertyValue("operand1").toInteger() 
log.info messageExchange.modelItem.testStep.testCase.getPropertyValue("operand2").toInteger() 
log.info conversionRate
log.info messageExchange.modelItem.testStep.testCase.getPropertyValue("operand1").toInteger() + messageExchange.modelItem.testStep.testCase.getPropertyValue("operand2").toInteger() == conversionRate

When I execute it logs the following:

Sun Mar 13 15:22:53 IST 2016:INFO:122
Sun Mar 13 15:22:53 IST 2016:INFO:12
Sun Mar 13 15:22:53 IST 2016:INFO:134
Sun Mar 13 15:22:53 IST 2016:INFO:false

It's giving me false instead of true . Shouldn't it be true instead of false ?

Is conversionRate an integer as well?

def i = '122'.toInteger()
def j = '12'.toInteger()
def rate = '134'
println i + j == rate
println i + j == rate.toInteger()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM