Difference between Stub and Driver
Key Difference: Stub and Driver are two different types of codes that are used in software development, specifically in software testing. Stubs are used as functions in Top Down Integration, whereas drivers are used as functions in Bottom Up Integration. Stubs and Drivers are commonly used in porting, distributed computing, as well as general software development and testing.
Stub and Driver are two different types of codes that are used in software development, specifically in software testing. There are times during software development when a part of the code must be tested. This allows the developed to make sure that this part of the code is working fine before he moves on to the next part of the code. However, this part of the code may not function properly without inputs from the other parts of the code, which have yet to be written. This is where dummy codes come in handy.
Dummy codes are pseudocode, which basically means that they are fake codes that help stimulate the behavior of existing code. This means that the developer can used these dummy codes in place of the parts of the code that have not yet been written in order to replicate the outputs the original code will give. These outputs can then be used to test the part of the code that has been written.
Stubs and Drivers are two different types of dummy codes and hence are used differently. Stubs are used as functions in Top Down Integration, whereas drivers are used as functions in Bottom Up Integration. Stubs and Drivers are commonly used in porting, distributed computing, as well as general software development and testing.
Suppose that there are three pieces of code: A, B and C, and they run in that direction, i.e. A-> B -> C. Now code A has been developed and needs to be tested, but codes B and C still need to be developed, and code A will not run without the input of B and C. Hence, stubs are used in place of B and C. These stubs imitate the codes B and C and even give output that are similar to what B and C would give. This is called Top Down Integration, i.e. testing from the top to the bottom.
Similarly, imagine now that codes B and C have been developed and need to be test, however code A still needs to be developed, and likewise the other two codes won’t work without the inputs from code A. Hence, a driver can be used in place of code A. This driver would then imitate code A and give the input to B and C, similar to what the actual code A would. This is called Bottom Up Integration, i.e. testing from the bottom up.
Stubs and Drivers are basically routines that don’t actually do anything except declare themselves and the parameters they accept. The rest of the code can then take these parameters and use them as inputs. The stubs and drivers are just commonly used as placeholders for the routines, i.e. codes that still need to be developed. Hence, the stubs and drivers contain just enough code to allow it to be compiled and linked with the rest of the program.
Comparison between Stub and Driver:
|
Stub |
Driver |
Type |
Dummy codes |
Dummy codes |
Description |
Routines that don’t actually do anything except declare themselves and the parameters they accept. The rest of the code can then take these parameters and use them as inputs |
Routines that don’t actually do anything except declare themselves and the parameters they accept. The rest of the code can then take these parameters and use them as inputs |
Used in |
Top Down Integration |
Bottom Up Integration |
Purpose |
To allow testing of the upper levels of the code, when the lower levels of the code are not yet developed. |
To allow testing of the lower levels of the code, when the upper levels of the code are not yet developed. |
Image Courtesy: qadocs.blogspot.com, csis.pace.edu
Add new comment