Unit testing is verifying the individual units of code. Code coverage can be used to determine how much of the code is actually being tested by developers. The aim of unit testing is to execute each line of code, and so unit testing helps detect corner cases that wouldn’t otherwise be caught during functional tests. There are various methods of unit testing automation for every language; some examples are Gtest/Gmock, junit, Cunit. Unit testing support generally comes along with programming languages.
Benefits
Unit testing improves the quality of the code
Unit testing allows the programmer to refactor code or upgrade system libraries
Unit testing reduces defects in the newly developed features or reduces bugs when changing the existing functionality
Unit testing helps reduce the cost of bug fixes
Unit testing provides documentation of the system
Why Unit Testing?
Unit testing, especially test driven development, is a design or implementation activity, not a testing activity.