[英]Groovy Spock. How to verify interaction with two arguments method?
嘗試使用 Spock 模擬來驗證方法調用參數。 互聯網上的文檔和大多數示例都包含單個參數的示例。
如何在模擬方法調用中實現多個參數的捕獲和驗證?
interface MyAction{
String doSomething(int first, String second);
}
// spec
def "should do something"(){
given:
MyAction action = Mock()
when:
action.doSomething(123, "abc")
then:
// how to verify that (first == 123) and (second == "abc") ?
}
就像你為單個論點所做的那樣列出它們。
import spock.lang.*
class ASpec extends Specification {
// spec
def "should do something"(){
given:
MyAction action = Mock()
when:
action.doSomething(123, "abc")
then:
1 * action.doSomething(123, "abc")
}
}
interface MyAction{
String doSomething(int first, String second);
}
在Groovy Web 控制台中試用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.