Sunday, 13 November 2011

Unit Testing

This articles give the details about Unit Testing. Unit Testing represents the validation of the individual units of the source code works as expected. In programming point of view a Unit can be function, procedure or an individual program etc.,

Unit testing is normally done by the Developers and not by the end users.

Usage Of Unit Testing:

The main purpose of the Unit testing is to isolate/separate part of the applications source code and make sure that the each unit is doing the expected task. Unit testing provides bottom up testing approach.In this we are making sure that the each part of the source code is working as expected then will be integrated with other modules. In this way we can eliminate the issues at earlier stage.

It provides a sort of the living documentation of the system.Developers looking to learn what functionality is provided by a Unit and also provides an idea to that how to use the specific units. It gives a basic understanding of an API.Unit test cases embody characteristics that are critical to the success of the unit. These characteristics can indicate appropriate/inappropriate use of a unit as well as negative behaviors that are to be trapped by the unit. A unit test case, in and of itself, documents these critical characteristics, although many software development environments do not rely solely upon code to document the product in development.

Unit testing facilitates the change.It means that it allows the developer to refactor the code at later date and also make sure that the module is still working as expected. The test cases for the  unit testing can be written and also code change can be done easily.

When software is developed using a test-driven approach, the unit test may take the place of formal design. Each unit test can be seen as a design element specifying classes, methods, and observable behavior.

Unit testing provides an option to separate the interface from implementation. Because some classes may have references to other classes, testing a class can frequently spill over into testing another class. A common example of this is classes that depend on adatabase: in order to test the class, the tester often writes code that interacts with the database. This is a mistake, because a unit test should usually not go outside of its own class boundary, and especially should not cross such process/network boundaries because this can introduce unacceptable performance problems to the unit test-suite. Crossing such unit boundaries turns unit tests into integration tests, and when test cases fail, makes it less clear which component is causing the failure. See also Fakes, mocks and integration tests.

Instead, the software developer should create an abstract interface around the database queries, and then implement that interface with their own mock object. By abstracting this necessary attachment from the code (temporarily reducing the net effective coupling), the independent unit can be more thoroughly tested than may have been previously achieved. This results in a higher quality unit that is also more maintainable.

Like other testing types, Unit testing has its limitations.Testing can't be expected to catch every error in the program.We may have n number of ways to evaluate a unit. So, by using unit testing we can't execute all possible ways of executing a particular unit.So, we can simply tell that Unit testing will not be used to catch the errors caused due to integration.Unit testing should be done in conjunction with other testing activities. Like other testing, Unit testing can show the presence of the errors not the absence of the errors.

Back To Top