Test Driven Development - an introduction

Rashi Karanpuria
3 min readMay 29, 2017

If you are looking for an introduction to testing, I am sorry this article will do you no good. If you know development in this order:

write application logic -> write a few tests

then this article is for you.

Test driven development (TDD) although has the same basic steps but not in the same order. In TDD developer has to write the tests first before writing the logic. This might seem silly, I can already hear you saying how can I test a method I haven’t written yet. But that is the core idea behind Test Driven Development.

Test drive the development in TDD.

So here is the deal, you have to write the tests for the methods you have not written yet and using objects you have not implemented yet, and yes they will fail, they need to fail (if they don’t fail there is a whole different problem here). Sometimes they might not even compile. This is the core distinction between TDD and no TDD, we start by writing a failing test. Only after they fail that you create objects and methods that make the tests pass. And please note here dear reader that you only write the minimum necessary code to just pass those tests.
Some of you might have noticed a scenario that TDD puts completely out of question. No? Here let me state it out when you sit to code a new method you spend a lot of time staring into blank space trying to figure out all the things that the code might have to do in present, past and future. All this speculative…

--

--