【问题标题】:Groovy map compare key from one test step and value of another test step and assert if it's true or falseGroovy map 比较一个测试步骤的键和另一个测试步骤的值,并断言它是真还是假
【发布时间】:2022-08-18 22:21:03
【问题描述】:

我有这样的常规脚本:

def map = [\'Response\' : \'id\']

def p1 = context.testCase.testSteps[\"TestStep_1\"].properties
def p2 = context.testCase.testSteps[\"TestStep_2\"].properties

def result = []

def assertPropertyValue = { p1key, p2key -> 
    def temp = p1[p1key].value == p2[p2key].value
    log.info(\"Comparing $p1key, and $p2key values respectively ${p1[p1key].value} == ${p2[p2key].value} ? $temp\")
    temp
}
map.each { result << assertPropertyValue(it.key, it.value) }
assert result.each{it.value == true}, \'Comparison failed, check log\'

尽管 TestScript_2 的值与 TestStep_1 中的键不匹配,但我的 groovy 脚本不会断言为 false。 我得到以下日志:

Fri Aug 12 17:48:16 CEST 2022:INFO:Comparing Response, and id values respectively {\"code\":\"200\",\"timestamp\":\"Fri Aug 12 15:12:45 UTC 2022\",\"HttpStatus\":\"OK\",\"id\":\"8154b2d1-4f83-4b2c-b100-5dab36b37ab6\"} == 929c2a62-5c8a-4e85-bf65-776696503818 ? false

ID 不匹配,我希望我的 groovy 测试用例断言 \"\'Comparison failed, check log\'\"。 你知道为什么会这样吗?

    标签: java dictionary groovy soapui


    【解决方案1】:

    each 在 groovy 中的 List 上返回 List,因此由于您的 result 对象不是 null 也不是空的,那么您的断言总是返回 true

    如果您想检查result 列表中是否没有false 值,请尝试使用any

    assert !result.any{ it.value == false }, 'Comparision failed, check log'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 1970-01-01
      相关资源
      最近更新 更多