The most experienced developer in my current team has set a few hard rules based on best practices we should follow. Among them is "You never ever mock domain object". I asked him why we couldn't but he never had time to give me a proper answer. Now he's away for a week, and I reached a peak distrust to that rule, here's my situation.
My domain object has an Update method with several parameters, one being an interface for a calculator. It then updates a few fields, runs the calculators and assign its results to some other of its fields.
The proper unit test for the Update method itself is reasonably long.
Now I have some piece of code which do a few things then call Update on such a domain object.
I would normally mock the objects, and just check the Update method is being called with the proper arguments. But now, I have to test it's being properly called, by checking its fields and mocking the calculator then same way I did when unit testing the Update method itself. And I would have to do that everywhere the Update methods gets called.
How fun will it be when the Update method change a bit, and every of those tests suddenly break and need refactoring... I feels this rule is just like shooting myself in the foot..
So I need to know, why You never ever mock domain object"?
Updatemethod itself, which attempts to fulfill too many use cases at once."I would normally mock the objects, and just check the Update method is being called with the proper arguments": that doesn't tell you much on the correctness of the program.aggregate.Updateis part of a larger business process which you are attempting to test, but you feel the need to check the correctness ofUpdate()everytime. I agree, you shouldn't have to do this and you most likely dont either. Why can't you just check the ouputs of the larger process given the inputs, without checking the result of callingUpdate()specifically. If you are already unit testingUpdateon it's own that should be enough.Updateimplementation. From the look of things you don't seem to be testing the domain, but testing an application service perhaps? A mock would be fine in this scenario IMO, but if you can't have a mock then just use a helper class to generate a fixture and a fake call toUpdate()which you can reuse across your tests.