verify interaction in spock not working
groovy, spock
Solution
I found what is wrong.
When trying to verify the interaction with a stubbed method, you should include the interaction return values in the 'then' block
then:
1* mockService.method(_, "some string") >> mockOutput
Problem
I have a spock test similar to this: ``` def "test" () { given: def mockOutput = new Output() Service mockService = Mock() classUnderTest.service = mockService mockService.method(_, "some string") >> mockOutput when: def returnedObject = classUnderTest.run() then: 1* mockService.method(_, "some string") } ``` I am trying to verify an method call of a service inside a class but it does not work. Based on my debugging, the stubbed call that is suppose to return mockOutput is not working anymore. However, I am successful when Im asserting the returnedObject which is the mockOutput (with exactly the same given and when blocks): Note that the returned object of the service is the returnObject of the class calling it. ``` then: returnedObject instanceof Output returnedObject != null ``` What am I missing?