Unit testing means testing a class in isolation. To be able to do this any collaborator must at least be replaced by some kind of stub implementation of it. While this is definitely a good thing and appropriate in some cases it is really awkward if you have many collaborators and if these collaborators have a rather large number of methods.
Another problem with stubs is that they are not flexible enough to meet every use case, especially the special ones that hardly ever occur (except you spent hours programming the stub).Thus you need a more general and dynamic approach.
The solution is: Mock Objects.
Mock objects also take unit testing a step further. You do not just create a stub that acts as if it were real, you also verify that the class under test collaborates with the mock object in the expected way. That means for example that the class under test calls certain methods with certain arguments on the mock object.
To work efficiently with mock objects you of course need a framework that gives you the ability to create mock objects and work with them easily.
真是说到我的痛处,今天才刚刚发完感慨,google不到类似的工具,是不是自己也做一个EasyMock for Delphi啊?
Crying for EasyMock for Delphi....
最新推荐文章于 2024-05-30 09:37:16 发布
Simon Wacker 在
Unit Testing: Mock Objects Framework
中写到: