According to wikipedia following are the steps in TDD:
step 1: Write a unit test
step 2: run the unit test
step 3: write code for module
step 4: run ALL tests again
step 5: clean up code
step 6: repeat the steps
Question 1 : in TDD we mainly write unit tests. Where do integration tests and system tests fit in the above steps?
Consider the following example:
Suppose we have a feature which we have to develop. Then according TDD, we will develop this feature in short iterations. Suppose we have divided this feature into 2 modules – module 1 and module 2. I am writing iteration steps for developing these modules in TDD according to above given steps. (Question 2) Please correct me where I am wrong in the following steps:
**Iteration 1: **
Step 1: we write unit test for module 1.
Step 2: Run this unit test for module 1(this test would fail)
Step 3: Develop code for module 1.
Step 4: Run unit tests for module 1 again(this test would pass)
**Iteration 2: **
Step 1: write unit test for module 2
Step 2: run unit test for module 2
Step 3: write code for module 2
Step 4: run unit tests for module 1 and unit tests of module 2.(Question 3: Here in this step why are we running unit tests of module 1 as module 2 is in under test? If you say that is done because to test that whether module 2 does not break module 1 functionality then my question is that here we are testing only module 2. It is not integrated with module 1 yet so how it will break module 1?)
**Iteration 3: **
Step 1: create integration tests (Am I right here?)
Step 2: run integration tests (they will fail as module 1 and module 2 are not integrated yet)
Step 3: Integrate module 1 and module 2
Step 4: run all tests (unit tests of module 1, module 2 and integration tests)
(Question 4: Why in this step are we running unit tests of module 1 and 2?)
Iteration 4(when all modules are integrated):
Step 1: create system tests
Step 2: run system tests (they will fail)
Step 3: (Question 5:) What code should I write here as for system testing we do not write any code and according to TDD principles first we write tests then we write development code so what code we will write here?