2017-01-12 14 views
0

groovyで私のif条件に少し問題があります。出力後に状態が正しく表示されない場合

事実私が設定したプロパティ値を見て、JSONから渡されるレスポンスのすべてのインスタンスがプロパティ値と同じ値を含んでいることを確認したい場合は、一致する必要があります。今、私がlocation_idlocation_id_requestを記録すると、期待通りの値が得られています。しかし、私のifステートメントでは、位置IDが一致しないので、私のif条件が正しくないと信じさせているようです。正しいメッセージを出力するためにif条件を変更する必要があります。以下は

私は下にログ情報を持っているコードです:正しい順序で

import groovy.json.JsonSlurper 

def response = messageExchange.response.responseContent 
def json = new JsonSlurper().parseText(response) 

def location_id = json.reviews.location_id 
assert location_id != null 
def location_id_request = messageExchange.modelItem.testStep.testCase.getPropertyValue("locationid") 
assert location_id.every {it == location_id_request} 

log.info location_id_request 
log.info location_id 

if (location_id == location_id_request) 
    log.info "Good News, location match!" 
else 
    log.info "Test has failed, location do not match!" 

ログ情報:

location_id_request:INFO:000000 
location_id:INFO:[000000, 000000, 000000, 000000, 000000] 
if condition output:INFO:Test has failed, location do not match! 
+0

http://stackoverflow.com/questions/41524701/how-to-make-a-list-comparisonの複製本ではないですイン・グルーヴィー –

答えて

2

あなたはListで(Number?)Stringを比較する - それは勝ちました仕事。その代わり、location_idlocation_id_requestListに存在している与えられたかどうかをチェックしてみてください。

if (location_id in location_id_request) { //... } 
関連する問題