Understanding API Stubs
In the context of Software-Engineering, API-Stubs are minimal implementations of an Application-Programming-Interface used to simulate the behavior of a real component. They are primarily utilized during Software-Testing to provide canned responses to method calls, allowing developers to isolate the System-Under-Test from its dependencies. This is a fundamental practice in Unit-Testing and Integration-Testing.
The Role of Stubs in Development
A Stub acts as a placeholder for a complex or unavailable module. For example, in a Microservices-Architecture, if one service depends on another that is currently under development, the team can use Service-Virtualization to create a stub that mimics the required interface. This enables parallel development and reduces bottlenecks. Unlike Mock-Objects, which focus on verifying interactions and behavior, stubs are generally used to provide the state necessary for the test to proceed.
According to Martin Fowler's analysis of Mocks and Stubs, stubs provide predefined answers to calls made during the test, usually not responding at all to anything outside what's programmed for the test.
Stubs in Distributed Systems
In Remote-Procedure-Call (RPC) frameworks such as gRPC or Java-RMI, a stub is a client-side proxy that facilitates communication with a remote Server. The stub handles the Marshalling of parameters and the Network-Communication, making the remote call appear as a local function call to the Client application. More information on the technical implementation of test doubles can be found on the Wikipedia page for Test Stubs.