mock vs stub

80 阅读1分钟

都是Test Double的一种,不同的是:

Stub

Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test.

stub提供的是对对象的方法response,stub是状态校验。

91AD6770A42BBC5D6EEDC0150EFF59F1.jpg

Mock

Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

mock期望对象接收到的规范,属于行为校验。

image.png

Reference