This is my first question here, so i'll make it short and to the point.

When Writing unit tests, should you write them before or after you have made the underlying framework for them? This came up in a discussion between my CEO and President, and I wanted your opinion on this.

Personally, I have always wrote the code first, then wrote the unit tests, but what about you?

closed as primarily opinion-based by Ixrec, gnat, Bart van Ingen Schenau, user40980, durron597 Sep 6 '15 at 15:02

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    This is ambiguous. Is it before you write the unit testing framework or before you write a framework that you will be unit testing? – alternative Oct 14 '10 at 19:41

During. You're not going to get an entire framework done in one iteration. Your framework and unit tests should co-evolve simultaneously.

On a more micro scale, tests first, code second.


Write the unit tests first - they'll help you define your interfaces - starting from what functionality they expose down to the method signatures.


I would have to say unit tests first then coding. Even with the best will in the world, tight deadlines and other priorities will simply mean they will get pushed back or not done at all. Leaving a bigger headache for those who'll have to maintain the codebase.

Besides writing the unit test should help you formulate what your trying to achive.

Not the answer you're looking for? Browse other questions tagged or ask your own question.