1

I want to understand more this sentence found in Grails documentation:

If the test is concerned with proving that the test subject interacts with a collaborator in a particular way, use a mock. If the fact that a collaborator behaves in a certain way exposes a particular behavior in the test subject the outcome of that behavior is what you are testing, use a stub

Pang
  • 9,564
  • 146
  • 81
  • 122

1 Answers1

0

If you'd like to test how many times some method will be called use Mock:

2 * yourService.someMethod(*_) // test that someMethod will be called 2 times

If no - use Stub

Evgeny Smirnov
  • 2,886
  • 1
  • 12
  • 22
  • Evgeny is right. For a complete Spock test sample showing the different capabilities of Spock mocks, stubs and spies, see my answer [here](https://stackoverflow.com/a/24415828/1082681). – kriegaex Feb 01 '18 at 00:58
  • Yeah Thanks @Evgeny ..it seems this the right and brief reponse to understand more between mocks and stubs ...this article agree also your response and i think it is greaaat article to inderstand the difference with spock .https://semaphoreci.com/community/tutorials/stubbing-and-mocking-in-java-with-the-spock-testing-framework – rihabe berrich Feb 21 '18 at 11:04