Spock - extracting interactions to method

五迷三道 提交于 2019-12-06 21:25:36

问题


The spock documentation points out that you can extract assertions of then block to other method and add assert keyword before each assertion.

I would also like to extract interactions to helper method. I tried wrapping interactions with interaction closure block but that did not work.

Is it possible? If it is how to achieve it?


回答1:


Turns out you can. You have to wrap helper method call with interaction:

then:
    interaction {
         helperMethod()
    }

and then you can put interactions in a helper method like that:

def helperMethod() {
    1 * someObj.getInt() >> 2
}

I did it other way around (wrapped helper method body in interaction), that's why it did not work



来源:https://stackoverflow.com/questions/37830936/spock-extracting-interactions-to-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!