什么时候使用 mock,什么时候使用 stub 和 spock?
When to use mock and when to use stub with spock?
我想进一步了解 Grails 文档中的这句话:
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
如果您想测试某个方法将被调用多少次,请使用 Mock:
2 * yourService.someMethod(*_) // test that someMethod will be called 2 times
如果没有 - 使用 Stub
我想进一步了解 Grails 文档中的这句话:
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
如果您想测试某个方法将被调用多少次,请使用 Mock:
2 * yourService.someMethod(*_) // test that someMethod will be called 2 times
如果没有 - 使用 Stub