Why Write Test Code?


Why bother writing code to test something that the developers will test themselves while developing and that the main testers will be testing anyway? Simple answer: to improve the overall quality of the end product and the maintenance of that product.

What this means in practice is that the developer will be writing some test code as well as the application code. Of course, this is going to take longer than just writing the application and no test code ... or is it? There are other aspects involved with development and testing that having test code can benefit from.

Case 1
Let's first consider what happens when there isn't any test code written ...

Case 2
So how can having test code help with this vicious circle? Let's do the same again, but now include writing test code ...

Once these regression tests are in place, having the confidence and possibility to refactor when needed can be carried out without being afraid of what might break or having to retest the application by hand again. Bug fixes can be made, small additions to some use case can be made, each time running the tests to ensure all was working as it was previously. This benefits both the development and maintenance phases.

When a bug is found in the application, a test case can be written to prove it is there. When the bug has been fixed and the test case passes, you have another test case created and left in place that will ensure that the same bug doesn't creep back in.

Code coverage can be applied to check how much of the application code is exercised during testing and to help build up the test code to provide more (targetted) coverage for the application.

Technical problems that may have crept in are detected quickly and much less likely to end up causing delays in user testing, where testing should concentrate on the business aspects of the application.

So, to summarise ...

Benefits

Drawbacks


DeadEd.com
http://www.deaded.com/staticpages/index.php/whywritetestcode