2016-09-02 35 views
0

在我的斯波克測試類,我有以下兩個列表:Groovy的:從一個字符串列表彈出最後一個元素

@Shared def orig_list = ['東京(成田・羽田)', '日本','アジア' ] 
@Shared def dest_list = ['ソウル', '韓國','アジア' ] 


def "Select origin"() 
{ 
    when: 
    something() 

    then: 
    do_something() 


    where: 
     area << orig_list.pop() 
     country << orig_list.pop() 
     port << orig_list.pop() 
     dest_area << dest_list.pop() 
     dest_country << dest_list.pop() 
     dest_port << dest_list.pop() 
} 

但得到的錯誤:

java.lang.IllegalArgumentException: Couldn't select option with text or value: ア.... 

但如果我不去使用的地方塊和做像:

def "Select origin"() 
{ 
    def area = orig_list.pop() 
    def country = orig_list.pop() 
    def port = orig_list.pop() 

    def dest_area = dest_list.pop() 
    def dest_country = dest_list.pop() 
    def dest_port = dest_list.pop() 

    when: 
    something() 

    then: 
    do_something() 
} 

比它工作正常。

如何從列表中獲取塊的值?有什麼問題?

回答

3

在where塊需要列表中定義的變量,但pop()方法返回列表中的一個元素,在你的情況下,它似乎是一個字符串。

無論是包裹list.pop()括號,這樣[list.pop()],或者更好,重寫你在那裏塊使用的列的語法,即是這樣的:

where: 
    area | country | port | dest_area | dest_country | dest_port 
    'a1' | 'c1' | 'p1' | 'da1'  | 'dc1'  | 'dp1' 
    'a2' | 'c2' | 'p2' | 'da2'  | 'dc2'  | 'dp2' 
+0

非常感謝你的幫助的解答。我沒有注意到那裏的街區在哪裏。 –

相關問題