Originally posted by SpontaneousOrder
View Post
Simple example - We take our Calculator class and add component B to provide some caching logic on top. TDD will allow you to verify the result but you won't be able to verify how the result was provided. Is B dipping into the cache or forcing a recalculation each time?
If you test them together, and you test drive your code, you'll never get unexpected nulls or garbage. That's the point.
Isolating everything as an overarching rule invites the problem of never knowing exactly how your collaborating classes may behave under any given circumstance, and therefore you write many tests that *should* be redundant - but are necessary for peace of mind.
You also write tests which cover both valid scenarios and invalid ones too - which is both wasteful and worsens the signal/noise ratio. This is why you can't really do proper TDD (as far as I'm concerned) while isolating every class.
Isolating everything as an overarching rule invites the problem of never knowing exactly how your collaborating classes may behave under any given circumstance, and therefore you write many tests that *should* be redundant - but are necessary for peace of mind.
You also write tests which cover both valid scenarios and invalid ones too - which is both wasteful and worsens the signal/noise ratio. This is why you can't really do proper TDD (as far as I'm concerned) while isolating every class.
The power of a solid set of unit tests can ensure that a class conforms to an exact set of behaviour, regardless of external factors. So a test that is potentially redundant today, might prevent a bug next month when other developers start trampling over the code.
But the principle is still the same. It is far better, where possible, to test behaviour rather than implementation, and behaviour is an emergent property of multiple collaborators - not a single class.
Leave a comment: