On the other hand, you could be faced with as change request to an existing, in production working application. The programmer needs to make some changes but you would like to assure that no inconsistencies creep in the existing code parts.
On the other side of the spectrum , there is a school of thought that considers test as a specification, a way to capture what a piece of software should be doing
Unit testing is a process of testing the individual subprograms (classes), subroutines or procedures (methods) in a program. It is one of the techniques to reduce the feedback period between writing code and looking for defects in the code and is done by the programmer. This test batches could also be used for regression testing. Currently a new wave of agreement on the importance of unit testing is acknowledged in the industry. Although unit testing isn’t something completely new, new automated tools that assist the developer is his/her unit testing effort have boosted the attention to this type of testing.
Unit testing adoption requires full management support because it requires that the individual programmers adapt to a new way of working that requires a slight mind shift. Unit testing is only one kind of test. These tests don’t make other types of testing like system testing, load testing or user acceptance testing redundant.
As stated before, unit test is not something new, but the way unit testing is now supported or integrated in development tools is. For example a very popular open source: Nunit (http://www.nunit.org/) is freely available and enables the individual programmer to write and conduct his unit test in a very quick and uniform way sported by a tool. Microsoft also has an integrated Unit testing framework into their VS2005 Team Edition for Software Developers product.
Unit tests are written to ensure that code performs as the programmer expects—how it will be consumed, used, disposed of, and how it reacts positively, negatively, and inconclusively under any circumstance.
Unit testing requires extra work but give plenty advantages
· Basis for regression testing when changes are made
· Indirect documentation and examples the usage of the API
Sometimes it is difficult to test a single unit in isolation because of its dependencies. Thought should be placed on designing code for easier testability for example via Interface based programming and Inversion Of Control. Or you should consider a tool like TypeMock (http://www.typemock.com/)
Although the automated unit testing tools originated from the XP School you do not have to exercise “write test first, code afterwards” (Test-driven development). You can write test afterwards or better concurrently with your code.
References and recommended reading
- Write Maintainable Unit Tests That Will Save You Time And Tears, Roy Osherove http://msdn.microsoft.com/msdnmag/issues/06/01/UnitTesting/
- Qualities of a Good Unit Test http://codebetter.com/blogs/jeremy.miller/archive/2005/07/20/129552.aspx
- Coder to Developer: Tools and Strategies for Delivering Your Software , Mike Gunderloy , ISBN:078214327X
- Pro Visual Studio 2005 Team System ,Jeff Levinson and David Nelson , ISBN:1590594606
- .NET 2.0 for Delphi Programmers ,Jon Shemitz , ISBN:1590593863
- Extreme Programming Refactored: The Case Against XP Matt Stephens and Doug Rosenberg ISBN:1590590961
- Professional Visual Studio 2005 Team System ,Jean-Luc David et al. ISBN:0764584367
- Code Complete: A Practical Handbook of Software Construction ,Steve McConnell , ISBN:1556154844
- Test-Driven Development in Microsoft .NET, James W. Newkirk and Alexei A. Vorontsov ,ISBN:0735619484
- Pragmatic Unit Testing in C# with NUnit: The Pragmatic Starter Kit, Volume II (Volume Set) , Andy Hunt and Dave Thomas ,ISBN:0974514020
- Why Agile Software Development Techniques Work: Improved Feedback: http://www.ambysoft.com/essays/whyAgileWorksFeedback.html
- The Humble Dialog Box (http://www.objectmentor.com/resources/articles/TheHumbleDialogBox.pdf )
- NUnit (http://www.nunit.org/ )