Stubs and Drivers in Software testing

Life of software testers is never easy as they are asked to perform a thankless job of checking the codes written by developers and then bear the brunt of developers when they present the bug report. Often testers face the challenge of testing a part of module which is highly dependent on the module which is still under development. In such cases drivers and stubs come to tester’s rescue.

What are stubs and drivers?

They are a computer program which acts as a substitute of some other modules (which are not available for testing). These computer program will simulate the functionalities of the other modules thereby facilitating the software testing activity.

What are stubs?

Stubs are basically used in TOP-DOWN approach of integration testing. In this approach, the upper modules are prepared first and are ready for testing while the bottom modules are not yet prepared by the developers.
So in order to form the complete application we create dummy programs for the lower modules in the application so that all the functionalities can be tested.

Four basic types of stubs are as follow:

  1.  Display a trace message which is used by the modules being tested
  2.  Display the parameter values which are used by the modules
  3.  Return the values which are used by the modules
  4.  Return values selected by the parameter which are used by the modules being tested.

Example of stub
Suppose if we have an application in which there are three modules, say Login, Add student and Cancel Admission. Now suppose we are doing unit testing of the module Login and the modules Add Student and Cancel Admission are yet not prepared. Then we will create dummy modules for Add student and Cancel admission in order to carry out testing of Login modules. These dummy modules of Add student and Cancel admission are known as stubs. They receive instructions from login module and display the success or failure of login functionality.

What are drivers?

A driver is basically a piece of code through which other programs or pieces of code or modules can be called. Drivers are the main program through which other modules are called.
If we want to test any module it is required that we should have a main program which will call the testing module. Without the dummy program or driver, the complete testing of the module is not possible.
Drivers are basically called in BOTTOM UP testing approach. In bottom up testing approach the bottom level modules are prepared but the top level modules are not prepared. Testing of the bottom level modules is not possible with the help of main program. So we prepare a dummy program or driver to call the bottom level modules and perform its testing.

Example of the driver
Suppose we have an application in which three modules are there, say Login, Add student and Cancel Admission. Now we want to do the testing of the Add student module. Add student module cannot run standalone; first we have to enter into login page and then add student module will be executed. So Add Student module will be called by the Login module. Let us assume that Login module has not been developed by the developers. In this case we have to create a dummy module of Login which will call Login module and then the functionalities of the add student module will be tested. In this case Login module will be called as driver and the add student will be the module which is being tested.

Next we will discuss the difference in test stubs and test drivers in software testing.

Read More:
Benefits of Unit Testing
Advantages and Disadvantages of White Box Testing
Pros and Cons of Black Box Testing


Copyright © ianswer4u.com