Testability != Good Design

This post, comparable or not, now appears in the Everyday Unit Testing site. It’s on the idea that TDD equals good design, while it’s really not, and it probably still needs refactoring to get it to be good.

Check it out!

Image source: https://www.flickr.com/photos/microassist/7268711202/

5 comments on “Testability != Good Design”

  1. Anonymous Reply

    It is evident, that the isOverDrawn is not the property of the Customer, but the Account.
    What if the Customer has several accounts???

    So the more testable code pointed out some discrepancy in your design, at least…

  2. Gil Zilberfeld Reply

    Ah, you introduce domain knowledge into the story. Well played.

    Note, it is not evident, but assumed 🙂 I agree that well designed code explains the domain. I have failed in this example, because of my assumptions…

  3. Anonymous Reply

    The “evidency” comes from the line “getAccount().getBalance()>limit”, which seems to break the simple responsibility principle, so it is not a domain knowledge.

  4. Gil Zilberfeld Reply

    It also breaks the Law of Demeter. It’s not a SOLID code, and it still deserves to be tested.

    I’ll try to make my examples clearer in the future. My intention was to explain the costs of changing the code to testability for the overall design.

    Good design is in the eye of the beholder. SOLID is thought to be a good bar by many. But not always and not by everyone. Singletons may be evil to some, but are a good solution to others.

    I think I’ll write on this in a separate post.

    Thanks for the feedback,
    Gil

  5. Anonymous Reply

    Define good design first.

    If you define it as SOLID, then easily testable code is well designed.

    If you define it as code which costs the least for initial development and subsequent maintenance, then easily testable code is well designed.

    Code being easily testable may not be the only characteristic of good design, but it’s an extremely important one.

Leave a Reply

%d bloggers like this: