Advantages/Benefit of Unit Tests
•
The unit tests serve as the first users of your system and will frequently identifydesign issues or functionality that is lacking.
•
A well-written test suite provides the original developer with the freedom to pass thesystem off to other developers for maintenance and further enhancement.
•
Cheaper cost - It is a component that comes along with the MS Visual StudioIDE.
•
Disciplined Development - Well defined deliverable for the developer and morequantifiable progress. Often, just considering a test case will identify issueswith an approach/design.
•
Facilitates change and Reduces code fragility – Unit testing allows theprogrammer to refractor code at a later date, and make sure the module stillworks correctly (i.e. regression testing).
•
Simplifies integration - Unit testing helps eliminate uncertainty in the piecesthemselves and can be used in a bottom-up testing style approach. By testingthe parts of a program first and then testing the sum of its parts, integrationtesting becomes much easier.
•
Documentation
-
Unit testing provides a sort of "living document". Clients andother developers looking to learn how to use the class can look at the unittests to determine how to use the class to fit their needs and gain a basicunderstanding of the API.
•
Relative cost to fix defects graph - The earlier an error is caught the cheaperit is to fix.It takes the typical developer time and practice to become comfortable with unittesting. Once a developer has been saved enough time by unit tests, he or she willlatch on to them as an indispensable part of the development process.Unit testing does require more explicit coding, but this cost will be recovered, andtypically exceeded, when you spend much less time debugging your application.
Writing effective unit tests
•
Always separate your unit test assemblies from the code you are testing.
•
Avoid altering the code you are testing solely to allow easier unit testing.
•
Each test should verify a small slice of functionality. Do not write longsequential unit tests that verify a large number of items.
•
All tests should be autonomous. Avoid creating tests that rely on other teststo be run beforehand.
Leave a Comment
awesome awesome stuff....detailed and easy to understand. Ashok.