What is Unit Testing

Unit Testing

An insight of Unit testing reasons to employ unit testing

Unit testing is a method of testing each source code at individual level. The source codes are determined whether they can be freely used or not. Unit testing comes under software development phase that has all small testable portions for applications. Each of these codes are individually scrutinized and made for proper operation. Unit testing can be done manually as well as automated.

Characteristics of unit testing:

1)      Unit testing involves is vital to tests that are under unit test.

1)      Source code could be modified easily for functioning of program or source code, in unit testing.

2)      Unit testing may be time consuming and tedious.

3)      Patience and thoroughness is required to be with you when you use unit testing.

4)      Documentation need to be maintained in unit testing.

Steps for conducting unit testing

Main purpose of unit testing is to find any errors by conducting tests in program unit test plan. There are several steps required in conducting unit tests:

1)      Review program unit: You can use several techniques to carry on review of program unit. It is a necessary step before you start with unit testing. This can be done using static analysis technique like desk check, inspection or structured walk through. You can even use automated static analysis tools to get in to this process.

2)      Conducting code execution tests: There are dynamic analysis techniques that you can use in conducting code execution tests. To assist with this process, you can also use automated dynamic tools such as coverage monitors, memory analysis tools etc. In unit testing, test programs are performed one at a time. This helps in identifying errors very easily. This is because you look at all little errors one by one. As soon as coding is complete, program units are tested immediately. It may be necessary to use temporary modules that may be simulating with real modules.

3)      Use of drivers and stubs: In unit testing, you need to write drivers and stubs. These driver modules are used to simulate a calling module and then call a unit program that is being tested. They are passed with specific input arguments. Drivers could be written in many ways. You can either prompt them interactively for input arguments or let it accept input programs from a file.

Now, when you want to test the ability of unit that is being tested to another module, it is necessary to make use of another module that is called stub. You may use more than one stub at a time. It depends on total number of program units that are participating in testing. Now, you have many ways of writing stubs too. You can either return control immediately or return a message that indicates its calling and then write back the received inputs.

4)      Identification and resolving power of any discrepancies: Here is the step where you compare the actual result to the expected result. If there is no bug then that is recorded as non-discrepant program unit test plan. If there is any kind of error then you need to find them and fix them. if you find error in code then you can use following methods:

1        Isolating cause of error


2        Correction and then recompiling the program

3        Retesting the program again

If there is some error in expected result, then you need to correct that error. Further, re runs the test. As you correct all bugs and errors in unit testing, you must re execute the full unit program. There may be any unit metrics required while checking these and you must list them individually. Later on with use of evaluating test metrics, you can identify methods for gathering these test metrics.

5)      Determining completion of test: You find the unit test to be complete when :

1        You have finished executing tests that are itemised in program unit test plan.

2        You are satisfied that the code is able to match the required design.

3        You have finished correcting and re testing of errors.

4        You are documenting the test results in the program unit test plan.

unit testing

unit testing


Benefits of unit testing

Main aim of unit testing is to isolate all small units of codes and then show that each small part is error free. There are many benefits of unit testing.

1)Simplifies integration: As testing is done in each small unit of code, all similar codes are found to be integrated. At this step, it becomes ready for integration testing.

2)Helps in facilitating change: With the help of unit testing, you can even re factor code at later stage. This will help you to make sure that the code works properly. In this way, there is facilitation in writing test cases. Now, even you can make changes accordingly. With the help of unit testing, you can make changes in code easily.

3)Good documentation: Immediately after doing the unit testing, there is good documentation that is being needed. With unit testing, you are able to identify the characteristics that are making your application to have success.

4)Designing: Unit test plays the role of a rough and formal design that is necessary. This is because each unit test determines design element that is being used for specifying classes, methods and observable behavior.

Application of Unit Testing

1)Unit testing could be used in extreme programming and this relies on unit testing framework.

2)Techniques: With the use of automation techniques, you can help to find the correctness of unit testing.

3)Language level support: Unit testing also help in providing language level unit testing support.

4)Framework supports: Unit testing provides good unit test frameworks that uses assertions, exception handling and all other major things to carry on unit testing.




Fig: separating database layer in unit testing

Unit testing is the first step of testing and if this is carried out well, it opens your application to move further level of testing and then to success of your application.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>