- Joined
- Feb 28, 2016
- Messages
- 14
- Likes received
- 0
- Thanks received
- 0
Lets suppose you're doing the TDD thing... if you isolate every class you're throwing away 50% of the value of TDD, as TDD is all about emerging relationships between classes & components.
TDD and Unit Testing are not the same thing, and doing one doesn't mean you can't do the other.
If you have complicated logic in A coupled to complicated logic in B, then most of the time you've got a bad design. If you have complicated logic in A coupled to more trivial logic in B, then testing A & B together with a mocked C is often even better.
There is a time and a place, which is the point being made. Getting more benefit from isolating a single class, as opposed to from a small gaggle of cohesive classes operating together is, in my opinion, fairly rare. Hence I'd expect to see things like factories which return pre-assembled components being injected more than I would expect to see every single dependency being wired up in some layer of indirection.
Agreed that in some cases, where there is a natural coupling between classes, that it makes sense to test the classes together (the classic example would be the CalculatorInputParser and Calculator). I'd argue this isn't the norm though.
A good example for isolating classes might be if B is a UserPreferenceService, and A reads out a preference which is then used to drive some further logic in A.
How can you verify how A behaves correctly based on all the possible return values for this preference?
How can you confirm A behaves gracefully if B throws an exception, return null, returns garbage, or doesn't return at all?
