mock(test doubles) and stubbing 测试


mock 和 double 都是仿冒品,假的
测试中的合作者不存在,就搞一个假人放在那假装.

stubbing 是stub的现在分词. 
表示一个动作,就是踢一个...的动作.
因为有假人的问题, 现在假人不会和你合作, 怎么办?
就帮假人做点事, 假装是假人在做的. 
好比你把球踢给假人, 然后自己把球捡回来, 同时说一句假人把球踢给我了.
假设所有踢给假人的球都踢回来了/也可以是设定为不踢回来,就是要一个结果. 这个就是stubbing

A stub method is a method that just returns a simple but valid (though not necessarily correct) result.

They are typically made when building the infrastructure and you don't want to spend time on every method needed right now. Instead you create stubs so everything compiles and your IDE's auto-complete knows about the methods you are planning to use.

Another place where stubs are used is in mocking when testing, You supply stub methods instead of the normal dependency through dependency injection which return fixed results and then ensure that the code does the right thing with them. This isolates testing to the code you are trying to test and means you don't need to spin up a database just to run those tests.


阅读量: 915
发布于:
修改于: