[英]Groovy: pop the last element from a string list
在我的Spock測試課程中,我有以下兩個列表:
@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: ア....
但是,如果我不使用where塊並喜歡:
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()
}
比它工作正常。
如何從列表中的where塊中獲取值? 怎么了
在where塊中期望列表中定義的變量,但是pop()方法返回列表中的一個元素,在您的情況下,該元素似乎是字符串。
可以像這樣[list.pop()]
將list.pop()
括在方括號中,或者更好的辦法是重寫您的where塊以使用列語法,例如:
where:
area | country | port | dest_area | dest_country | dest_port
'a1' | 'c1' | 'p1' | 'da1' | 'dc1' | 'dp1'
'a2' | 'c2' | 'p2' | 'da2' | 'dc2' | 'dp2'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.