Wednesday, 7 August 2013

Unit Testing and its Importance in Software Development

As a tester my curiosity to know how the developers will test a piece of code makes me to write this post.

Unit Testing
It is a familiar word used mostly by the developers, writing  a piece of code to verify/validate the code written for implementing the requirements irrespective of any programming language is called as unit testing. Usually it is mostly done by developers/ white box testers. 

Classic definition of unit testing "Unit testing is the method of verifying smallest piece of testable code against its purpose".

Why unit testing ? 

Main purpose of unit testing is to maintain good quality of the code and also to avoid issues/bugs in units of the code. As a good practice of SDLC it is important to find the bugs/defects at the earlier phases which will give better ROI to the companies, if we follow writing unit tests as a standard process of developing maximum defects will be found in the initial phases itself so that we can save much testing time.

Advantages 
  1. Testing can be done in the early phases of the software development life cycle when other modules may not be available for integration
  2. Fixing an issue in unit testing can fix many other issues occurring in later development and testing stages
  3. Cost of fixing a defect found in unit testing is very less than the one found in the system or acceptance testing
  4. Coverage of the code can be measured
  5. Fever bugs in the system and acceptance testing
  6. Code completeness can be demonstrated using unit tests. This is more useful in agile process. Testers don’t get the functional builds to test until integration is completed. Code completion cannot be justified by showing that you have written and checked in the code. But running unit test can demonstrate code completeness.
  7. Expect robust design and development as developers write test cases by understanding the specifications first.
  8. Easily identify who broke the build
  9. Saves development time: Code completion may take more time but due to decreased defect count overall development time can be saved.
List of popular unit testing tools

1. Java framework  - JUnit
2. PHP framework - PHPUnit
3. C ++ frameworks - UnitTest++
4.  .NET framework - NUnit
5. Python framework -py.test