A replacement implementation for objects, methods, or functions in order to remove external dependencies, or the object at the client end of an RPC or RMI invocation.
A replacement implementation for object, method, or function. The typical types of stubs are:
- Testing stubs that remove external dependencies. They are typically used during unit and component testing. If you're trying to write a unit test and need to replace a simple call to a database, external libraries (e.g., file I/O) or other system API, stubbing might be perfectly suited for your needs.
- RPC (CORBA, RMI, web service) stubs forward the call to remote service where it is handled; the answer, if any, is returned to the calling side. They implement the same interface that is implemented by the servicing object on remote side (may also implement additional interfaces).
- Dummy stubs are empty placeholders for objects, methods or functions that are supposed to be completed later. They allow the current code to compile so that other, already finished parts could be tested. Such stubs are used when implementing a very large libraries following some already specified API.
A mock is somewhat similar to the testing stub but is not considered stub as it is a special purpose object capable of registering that has been called on it. It does not take other actions (a generally unfavoured partial mock does forwards execution of some methods to underlying object).