# Unit Testing

Unit testing ensures that each part of the code developed in a component delivers the desired output. Whenever the application is ready and given to the Test engineer, he/she will start checking every component of the module or module of the application independently or one by one, and this process is known as **Unit testing** or **Component testing**.

<div data-full-width="true"><figure><img src="https://static.javatpoint.com/tutorial/software-testing/images/unit-testing.png" alt=""><figcaption></figcaption></figure></div>

## Unit Testing Techniques

Unit testing uses all [white box techniques](https://qatesting.gitbook.io/qa/manual-testing/types/white-box-testing) as it uses the code of the software.

### How to achieve the best result via Unit testing?

Unit testing can give best results without getting confused and increase complexity by following the steps listed below:

* Test cases must be independent because if there is any change or enhancement in requirement, the test cases will not be affected.
* Naming conventions for unit test cases must be clear and consistent.
* During unit testing, the identified bugs must be fixed before jump on next phase of the SDLC.
* Only one code should be tested at one time.
* Adopt test cases with the writing of the code, if not doing so, the number of execution paths will be increased.
* If there are changes in the code of any module, ensure the corresponding unit test is available or not for that module.

## Advantages

* Unit testing uses module approach due to that any part can be tested without waiting for completion of another parts testing.
* The developing team focuses on the provided functionality of the unit and how functionality should look in unit test suits to understand the unit API.
* Unit testing allows the developer to refactor code after a number of days and ensure the module still working without any defect.

## Disadvantages

* It cannot identify integration or broad level error as it works on units of the code.
* In the unit testing, evaluation of all execution paths is not possible, so unit testing is not able to catch each and every error in a program.
* It is best suitable for conjunction with other testing activities.
