In software development projects, unit testing is a software validation type where the coder verifies each units of source code versus its specification. A unit is nothing but a most atomic testable part of a developed application program. In procedural computer programming single program, function, procedure, etc. can be considered as unit. In object-oriented computer programming, the smallest unit is a method, that may lie in to a base/super class, abstract class or derived/child class.
As per Microsoft:
The primary goal of unit testing is to take the smallest piece of testable software in the application, isolate it from the remainder of the code, and determine whether it behaves exactly as you expect. Each unit is tested separately before integrating them into modules to test the interfaces between modules. Unit testing has proven its value in that a large percentage of defects are identified during its use.
The most common approach to unit testing requires drivers and stubs to be written. The driver simulates a calling unit and the stub simulates a called unit. The investment of developer time in this activity sometimes results in demoting unit testing to a lower level of priority and that is almost always a mistake. Even though the drivers and stubs cost time and money, unit testing provides some undeniable advantages. It allows for automation of the testing process, reduces difficulties of discovering errors contained in more complex pieces of the application, and test coverage is often enhanced because attention is given to each unit.
Here are a few Best Practices:
1. The print out of a unit should reside on a single sheet of paper.
2. If there are more than 4 levels of nested unit, then maybe it should be split in two.
3. Whenever the cyclomatic complexness of a unit is greater than 10 then it's getting excessively complex.
4. Whenever it is content-coupled with another unit then it Is not a good unit.
The process is:
1. Prepare a test Plan of the unit tests.
2. Design the tests, the test environment, and operator instructions.
3. Identify and get the test data.
4. Code and run the tests.
5. Analyse the results.
Related Posts:
1. Unit Testing vs System Testing
2. Test Levels
Click here to continue Reading this post....SPONSORED LINKS

