The Holy Java

Building the right thing, building it right, fast

Clean Test Design

How to design your tests so that they are maintainable, valuable, long-live, and help you develop defect-less code?


Stuff to include

  • Split into (ref.: Cohen’s Testing Pyramid)
    • focused private|public unit tests
      • test individual methods in isolation; focused, independent => can test more cases, more easily
    • module-level integration tests
      • test collaboration of few classes (real classes, no mocks) to verify they collaborate together as expected – verify that the methods tested in unit tests are actually used
    • end-to-end integration/functional tests
    • acceptance tests
      • make sense to the business (though usually written by devs), can form the basis of a system of “living documentation)



  • Mocks: Yes or not? (=> when yes?) – read Martin Fowler’s Mocks Aren’t Stubs that discusses mockist vs classical testing; quote (emphasis mine): “A classic test only cares about the final state – not how that state was derived. Mockist tests are thus more coupled to the implementation of a method. Changing the nature of calls to collaborators usually cause a mockist test to break.”

One Response to “Clean Test Design”

  1. […] (If you liked this post then you might also like Principles for Creating Maintainable and Evolvable Tests, Never Mix Public and Private Unit Tests! (Decoupling Tests from Implementation Details) and Clean Test Design.) […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: