unit testing - mock out return of a method base on the number of invocation only in spock -


Is it possible to copy the return value of a method based on NT time? Note that I do not want to specify passed parameters because it does not matter for a specific test case. For example, for the first call it should be returned, it should be returned for the second call.

Yes it is possible.

  someObject.someMethod (* _) & Gt; & Gt; & Gt; ['X', 'Y']  

This will return to the second invitation of the method on x and y .

example:

  zero "test something" () {given: def sample = duplicate (sample) {some method (_) & gt; & Gt; & Gt; ['Hello', 'world']} Hopefully: sample.someMethod ('foo') == 'Hello' sample. Some method ('bar') == 'world'} Sample of class {def someMethod (Df A ) {Return A}}  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -