Login  Register

Re: [ANN] BabyMock 2

Posted by Attila Magyar on Apr 24, 2014; 9:21am
URL: https://forum.world.st/ANN-BabyMock-2-tp4748530p4756179.html

I made up an example because it makes easier to talk about this. Let's say, I want to test the #addAll: method of the OrderedCollection. If #addAll: is implemented as a loop that uses the #add: method (itemsToBeAdded do: [:each | self add: each]) then would you test the #addAll: isolated from the #add:? I think it would be a bad idea, because we're talking about an implementation detail. The #addAll: could have been implemented in a different way. Mocking the #add: couples the test to the current implementation and makes it brittle. If I change the implementation of the #addAll:, then the test will need to be changed as well, even if the functionality remained the same.

You're right that if there is a bug in the #add: then 2 test cases will fail, instead of one (the localization is worse but the test is less brittle).
But if I implement it in a different way, where the 2 methods have separated logic then only one will fail.

Don't know if this example applies to you case or not.