Thursday, January 31, 2008

Leveraging functional test cases to perform Unit Tests

Ever since I have worked with quality process improvement I have heard a lot of excuses for not doing unit testing as it is wonderfully articulated in this article Excuses for not doing unit tests. Subsequently I have found that we are spending almost 50% of our total project effort on testing and defect fixing and the reason for this is because there is not enough unit testing done. So this got me wondering as to how we can change the process so that we can have more efficient unit testing done so that the defect fixing and testing effort comes down.

As per the process after having the requirements defined we give off the same requirements specification to the development team (for design and development) and to the independent testing team (for developing the functional test cases). The functional test cases are developed using this template. Once the development team completes the design document it is used as an input to enhance the functional test cases to cover all the test cases that might have got missed by looking at only the requirements. Usually half way through the development cycle the testers have completed the functional test cases and are ready for the testing to begin.

If a defect is found by the testing team there is a high cost involved in fixing it (in terms of effort) for the following reasons
  • Time taken by tester to identify the defect and log it
  • Time taken by the development lead to analyse the defect and assign it to the developer
  • Time taken by the developer to fix the defect and change the status in the defect tracking tool
  • Time taken by the tester to retest the defect and close it

Given the high cost I was wondering why shouldn't the first round of testing be done by the developer themselves on the code that they developed. This may take a bit of extra time for the development team but the cost of finding a defect and fixing it is lower. The costs involved here are

  • Time taken by the developer to understand and execute the test case
  • Time taken by the developer to fix the defect

The following are the advantages that I see in this process

  1. The time taken to identify defects and fix them comes down drastically since we are removing a whole loop involving the tester. Yes the development time goes up marginally but the benefits if 90% of the defects that were slipping through are identified and resolved at the development stage itself then it well give us good overall time lines.
  2. The development team can identify if there are any test cases that are not right or that are for functionality that is not being developed. This will reduce the number of rejected defects. Rejected defects take the same amount of time as a simple defects since the only thing missing in that cycle is the development effort.
  3. The development team will become more aware of the testing that is going to happen and will automatically lift the quality of the code that is written by them.
  4. It formalizes the unit testing. The developer can use the functional test cases as a guide to do their unit testing.
  5. The cost of fixing the defect as soon as the code is developed is a lot less expensive than fixing the defect at a later date as the code is still fresh in the developers mind.

No comments:

You do what you are

In the 2001 movie Along came a spider, there is an interesting quote by Morgan Freeman where he says "You do what you are" and the...