About Unit Testing
– Unit testing is defined as a means or a technique using which the individual units in the code of the program can be tested.
– This type of testing lets you combine together the different modules of the program and test them as a group or one single unit.
This testing is carried out with the help of the following three things:
– The units are tested using the above three things to decide whether they are fit to be used or not.
– In the concept of the unit testing, one unit can be viewed as the smallest part of the program code that can be tested.
– An entire module can be taken as one unit in the case of the procedural programming but usually an individual procedure or function is taken as one unit.
– On the other hand, the entire interface or class can be taken as one unit in the object oriented programming.
– Sometimes the white box testers might create the unit tests during the development stage but usually this task is accomplished by the programmers.
– In an ideal case, one unit test does not depend on the other units.
– Further, if some sort of assistance is required for testing the units in isolation, substitution objects such as mock objects, method stubs, test harnesses, fakes and so on can be used.
– Software developers are responsible for running unit tests and ensuring that the standards are met by the design of the code.
– They also check whether the modules behave as expected or not.
– The implementation of the unit testing can be done automatically or manually.
– The manual approach is quite informal and is carried out using pen and paper.
– The automated approach is a more formal approach and is carried out as a part of the build.
There are several benefits of unit testing such as it allows facilitating the changes, finding problems earlier in the development cycle, simplification of the integration, documentation and so on.
But there are limitations also for unit testing.
– In the trivial programs, every execution path cannot be tested and therefore unit testing cannot catch all the errors in the code of the program.
– Further, only the functionality of the unit is tested by the unit testing and therefore it will not catch the errors in the integration.
– This means the system error at the broader level cannot be caught in unit testing.
– Another drawback of the unit testing is that it has to be carried out along with some software testing activities since it is capable of showing only the absence or presence of certain errors.
– Unit testing is not enough for proving that there are no errors, additional techniques are required.
– Software testing is no simple straightforward problem rather it’s a combinatorial problem.
– This causes the programmer to write few lines extra for the test code which obviously increases the coding time and in some cases the amount of time and money you put into it might not be worth it.
– Above all, there are some problems which cannot be entirely tested for example, the problems involving multiple threads, non – deterministic problems and so on.
– In addition to the test code written for testing, the unit can also have as many bugs as the source code itself.
– Also, the unit tests always present the challenge of setting up tests that are both useful and realistic.
– In order for the unit testing being successful it is necessary that some initial conditions should be set up prior to testing.
– These conditions make the unit behave as if it is connected to the entire system.
– A lack of proper initial conditions won’t allow the unit to be tested in the real context thus diminishing the accuracy and so the value of the result.