liveBook · Manning

Stub

As explained in Troubleshooting Java, Second Edition

A stub is a controllable fake application or component that substitutes for a real dependency during investigation or testing.

A stub is a controllable fake application or component that temporarily replaces a real dependency. It lets you investigate interactions without relying on the dependency’s normal behavior. section 1.2.1

Use a stub when the source of an unexpected interaction is difficult to locate:

  • Replace the component receiving the wrong request with a stub. section 1.2.1
  • Make the stub block the request so the application waits indefinitely. section 1.2.1
  • Use a profiler to identify the application code stuck waiting for the stub. section 1.2.1
  • After correcting the problem, use the stub again to test the solution. section 1.2.1

Finding the source of an erroneous request

An application sends a request to the wrong system component. When the real recipient is replaced by a stub that never responds, the application remains blocked. Profiling the blocked execution reveals which code issued the request, giving the investigation a starting point before using a debugger. section 1.2.1 section 2.3

Figure 1.8 You can replace the system component your app calls with a stub. You control the stub to determine where your app sends the request from quickly. You can also use the stub to test your solution after you correct the problem.

Shows how replacing a called system component with a controlled stub supports both investigation and verification. section 1.2.1

How Troubleshooting Java, Second Edition covers it

How deep it goes
Defines the technique and gives a blocking-request workflow, but defers implementation details of stubs and profilers.
Examples
Uses a wrong system-component request, an indefinitely blocked response, and profiler output identifying the stuck code.
What it assumes
Starts from an observable wrong output and distinguishes when a profiler or debugger is needed to locate its source.
What you can do after
Diagnose/debug with it by isolating a dependency, locating request-producing code, and testing a repaired interaction.
How it connects
Connects stubs with debugging, profiling, logging, thread dumps, heap dumps, and the Heisenberg effect.

Also explained in

Compare how 10 books explain stub →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.