What is Unit Testing?
Testing the smallest piece of code or a software component is known as unit testing. Every individual component is tested, and it is the first level of functional testing. It checks for correctness of the code. This process is carried out during the development of an application. Unit testing is used to validate each unit of the software that is designed to perform.
Why Unit Testing is done?
We move forward using unit testing because it would save cost and effort during the development cycle. Ensuring that the individual parts are working well, unit testing is performed. Changes can be made quickly using testing code-base. The unit testing code can also be reused. Bugs can easily be fixed in the early stages of SDLC even before they become expensive for the enterprises to fix when identified at a later stage.

OBJECTIVES OF UNIT TESTING:
1.Check for correctness of the code.
2.Code can be re-used.
3.Changes can be made quickly.
4.Isolate the section of code.
5.Saving cost by fixing the bug in the early development phase itself.
TYPES OF UNIT TESTING:
1.Manual
2.Automated
Enterprises prefer using automated testing to manual testing as effort needed is less for automated rather than for manual testing. In manual testing, documentation with instructions is needed which would be essential for unit testers.
TOOLS USED IN UNIT TESTING:
1.JUnit
2.NUnit
3.JMockit
4.EMMA
5.PHPUnit
6.HTMLUnit
7.TestNG
8.Jtest
WORKFLOW OF UNIT TESTING:
1.Create test cases.
2.Review and change
3.Baseline
4.Execute
a) Create test cases:
Developers will write the code and test it in an application and will wait for the application to get deployed.
b) Review and change:
The code is isolated for validating dependencies between the codes and other units by the developers. Thus, the code helps in identifying and eliminating the dependencies.
c)Baseline:
Usage of unit testing tools or unit testing frameworks are significantly used for developing automated test cases
d)Execute:
Flagging and reporting test cases can be made if the test case failed while executing the test cases. The unit testing related to that test case may stop if test case fails multiple times.
BEST PRACTICES:
1.Only a unit of code should be tested at a time.
2.Naming conventions used in the code should be clear and consistent.
3.Enhancement or change in the requirements should not affect the unit test cases.
4.Identified bugs should be fixed immediately and then move on to the next phase in SDLC.
5.Unit test cases should be independent of each other.
6.Should separate production code and test code.
7.Should stick to one unit code only at a time.
ADVANTAGES:
1.Cost is reduced due to defects found during the earliest stage.
2.Reduces bugs and defects and develops features.
3.Refactoring the code can be done at a later date by the developer
4.Changes can be made in the existing functionality without affecting the unit test cases.
5.Improves design and nature of the modular code.
DISADVANTAGES:
1.Unit testing cannot be expected to find all the errors in a program.
2.It is difficult to evaluate all execution paths even in the most trivial programs.
3.Unit testing focuses on a unit of code. Hence it cannot find integration errors or broad system level errors.