Most projects I've come across use unit-testing as a method to verify code quality. A common issue is that mock objects are needed to satisfy the external dependancies a component has, and possibly to simulate the behaviour of these external components. I have come across two strategies as to who writes the mocks: a) either the one who needs the mock, or b) the one who owns the component you want to mock.
The problem with former option is it can mean a lot of additional work maintaining a mock such that it remains conform to the interface of the component you want to mock. What's more you have no control over that interface, and it may require you to maintain your mock if it is a java interface or it contains C++ pure virtual methods. Another point is that other component owners may also require mocks for that same component, so the danger is a multitude of mocks get created, sometimes badly maintained.
The option b) sounds much better but the problem here is motivating a component owner to maintain a mock of his component that is usually of no use to himself. I have found that as project deadlines becomes more challenging this approach gets more and more difficult to enforce.
Of course, if you have to mock 3rd party code, then there is no choice.
I'd be interested whether there are any other workable approaches or experiences anyone has come across.
0 Comments:
Post a Comment
<< Home