LKBEN11200: What is a software stub?


you would like to know what a stub is an how it can be used




A stub is a piece of code used to replace another programming functionality. (e.g. a Procedure for function) Instead of the original source code, the stub will be called. The software stub may simulate the existing behavior or even do nothing at all. In the latter case, you can think of using a stub as a temporary piece of software yet to be written. Stub are usefull in porting and testing software.

An example of a stub in c++ might be:

int GetWindSpeed(void)
    cout << "Here you connect to the device and get the speed back." << endl;
    cout << "Stub returns always 4!" << endl;

    return 4;

In the case above, you can compile and test your software without even having a hardware device. It just returns a "legal" value.

Most of the time you can think of a stub as a piece of code which declares a function with parameters the real function accepts. A kind of a placeholder with a known interface to make it possible to compile and link your application.


The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!

About the Author

Author: Wim Peeters - Keskon GmbH & Co. KG

Wim Peeters is electronics engineer with an additional master in IT and over 30 years of experience, including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.