Stateful API Testing Tools Across the Spectrum From Record-Replay to Full Simulation
Four testing approaches compared by which integration failures each can catch.

To test integrations against stateful APIs without hitting production, use a simulator that preserves resources across calls, applies state transitions, and delivers webhooks. Choose simpler tools when the test only needs endpoint responses or replay of a known sequence. Stateful API testing tools span distinct approaches, and the right choice depends on which failures the test must expose.
Why stateless mocks break multi-step integrations before you even reach staging
A customer creation request returns 201 with the ID cust_123, but the next request to GET /customers/cust_123 returns 404. The mock stored nothing. Its creation response looked correct in isolation, yet the read exposes the structural limit of stateless stubs.
A Stripe workflow makes that dependency concrete. It can create a customer, create a payment intent, confirm that intent using its ID, and handle a webhook. The customer ID is optional when creating the payment intent, but confirmation still depends on the intent created earlier. Fixed responses can imitate each endpoint without following those dependencies, so a team can spend half-day or longer debugging issues its tests seemed to rule out. If the testing tool cannot hold state across calls, it cannot test the integration, only individual endpoints.
What "stateful" actually means across the testing tool landscape
A stateless tool uses fixed response definitions to answer requests and does not remember earlier calls. A stateful tool maintains a data model across them. Writes change that model, reads show those changes, and deletes remove records. State machines also track transitions such as a charge moving from pending to succeeded. Webhook delivery takes the model further by linking resource mutations to the events that trigger the integration logic that runs next.
The distinction between a mock and a simulation concerns where that behavior runs. A mock runs in-process and intercepts calls inside test code, while a simulation runs as a standalone network process that the application calls over HTTP. Deployment architecture is a separate question from statefulness. That distinction affects how the tool fits into CI/CD and whether several services can share it. Neither an HTTP interface nor the word “simulation” alone establishes that a tool remembers writes.
The spectrum laid out: four positions from least to most stateful
Spec-driven stub servers generate responses from an OpenAPI description and are stateless by default. Record-replay captures real requests and responses, preserving a session as a frozen recording. Consumer-driven contract testing enforces agreement between provider and consumer expectations. Full stateful simulation runs a live data model that has state machines and webhook delivery.
These positions describe mechanisms. In particular, contract testing sits on a different axis from resource persistence, because its role is compatibility enforcement. Fault injection can work across the spectrum, so it has no fifth position of its own. A tool can keep state and still lack the ability to produce rate limits, network failures, or malformed responses.
Spec-driven stub servers: fast setup, honest limits, and the drift trap
Prism is a canonical spec-driven stub server. It takes an OpenAPI file and serves example or dynamically generated responses that conform to the schema, without a separate stub-definition step. Setup is fast because the specification supplies the response definitions. A request outside what the specification describes gets a 404, making that gap visible rather than concealing it behind an invented success response.
Fresh values can expose hard-coded ID assumptions, but neither dynamic nor example mode remembers that a resource was created. These stubs therefore require workflows that are independent of earlier writes, resource transitions, or mutation-triggered webhooks.
Their accuracy also depends on the specification. A stale or incomplete file produces correspondingly limited responses, while a mock that has not followed a specification update introduces another source of drift. The real API can also diverge without either artifact changing. Within those limits, spec-driven stubs remain a legitimate fit for individual endpoint tests, frontend development against an unfinished backend, and early API design validation.
Record-replay: fast fidelity from real traffic, frozen at capture time
Record-replay gets its test responses from a proxy or eBPF intercept that captures requests and responses during a session with the real dependency, then replays them in CI without calling that dependency. Hoverfly, the open-source tool from SpectoLabs, uses this capture-simulate model to preserve response patterns, headers, and network characteristics.
That fidelity is bounded by the captured session. A new timestamp or UUID can prevent request matching because the replay compares fresh identifiers against recorded ones. Changing the order of calls can cause the same problem. The recording supplies fixed responses that remain unchanged by accumulated state. The recording also lacks error responses and rare failures that did not happen during capture.
For stable workflows, that constraint can be acceptable. Replay is fast and deterministic, with no live API calls, rate limit exposure, or live-service credentials in the pipeline. However, captured payloads also become part of the simulation file, including any sensitive data they contain. Teams that use this approach must mask sensitive fields before committing recordings to source control. It works best for regression protection when known workflows use the same requests in the same order.
Consumer-driven contract testing: schema drift prevention, not runtime simulation
Pact checks the boundary between services that are deployed on their own. A provider can change a field type or remove a key while its own tests still pass, leaving a consumer to fail when it receives the changed response. The missing protection is agreement about the interface. Contract testing makes that agreement executable, rather than assuming that each team’s local tests cover the other side’s expectations.
With Pact, consumer unit tests assert the HTTP requests the consumer will make and the response structures it expects. Pact generates a JSON contract from those tests and publishes it to a Pact Broker. The provider’s CI pipeline retrieves the contract and replays its requests against the provider’s actual API code. Both sides must pass before deployment proceeds. This establishes compatibility for the schema expectations expressed in the contract.
Verifying that a preceding write persisted, that a state transition occurred, or that a webhook arrived requires checks beyond the response’s expected fields and types. Schema agreement also does not show how the integration behaves under faults. Pact is therefore suited to preventing provider changes from silently breaking consumers, while runtime simulation validates the sequences those consumers execute.
Full stateful simulation: what it takes to replicate a real API end-to-end
Full stateful simulation combines resource storage, transition logic, and event delivery in a running process. A POST creates a record that a later GET retrieves. A payment intent can move from requires_confirmation to succeeded, and mutations trigger webhook events. Inspecting sandbox state reveals which records exist at that point. Among these categories, this is the approach that can execute a complete workflow with chained IDs and changing state without touching the live API.
The fidelity boundary shifts from recorded responses to modeled behavior. FetchSandbox explicitly distinguishes integration patterns from vendor-specific business logic. Stripe’s test mode knows which specific card numbers succeed and which decline, but a generated sandbox does not use those rules. A passing simulated workflow therefore establishes that the application handles the modeled integration pattern.
Vendor sandboxes provide a separate validation layer. Stripe test mode and Plaid sandbox are stateful, but shared environments, rate limits, provider accounts, and the lack of offline operation make them a poor foundation for CI. They remain appropriate for final validation. For automated workflow gating, a command such as fetchsandbox run stripe --all can exit 0 on success and non-zero on failure, allowing the pipeline to test modeled integrations without live API calls, credentials, or rate limit exposure.
Fault injection as a first-class testing concern, not an afterthought
Keeping state does not show that an integration can handle failures. An integration also encounters 429 Too Many Requests responses with a Retry-After header, partial responses, connection resets, and fixed or random delays. A happy-path simulator leaves those behaviors untested. Fault injection is therefore a separate capability requirement, even when the underlying workflow model is complete.
Toxiproxy, Shopify’s open-source TCP proxy, introduces network and system conditions including latency, dropped connections, and bandwidth throttling. These faults exercise a different layer from resource state. The practical questions are whether the application’s circuit breaker trips correctly, whether retries respect Retry-After, and whether a 503 during webhook delivery leads to queuing or dropping the event. A tool that only returns successful responses cannot answer them.
AgentChaos, a 2026 paper, found that the most damaging faults for AI agents could arrive with a normal HTTP 200. They included structurally malformed tool responses and truncated message content. Infrastructure chaos tools rarely caught these faults because ChaosBlade and Rainmaker work at the HTTP or OS level instead of checking each field in the response body, while CrashFuzz targets node crashes and reboots.
Testing AI agents that call external APIs: why the stateful bar is higher
An agent that creates a resource and later retrieves it needs the same persistent model as a conventional integration. Multi-turn execution adds another dependency. The agent keeps context between calls, and its actions change the world in which later calls run. Testing one tool call in isolation misses failures that emerge only after earlier actions have modified that state.
ToolSimulator within Strands Evals addresses this through an LLM-backed wrapper around registered tools. It uses the tool schema, the agent’s input, and current simulation state to generate schema-valid, context-appropriate responses. Its share_state_id parameter links tools that use the same backend. With that shared state, later reads can see earlier writes in workflows such as booking, cart management, or database updates.
Model execution introduces a separate CI tradeoff. Calling a real model costs money and gives nondeterministic results, but recording model responses on a developer’s machine and replaying them in CI avoids both problems when the pipeline runs again. The model runs once for capture. This use of replay stabilizes known model outputs, but it does not turn frozen responses into a general stateful API model. Agent evaluation still needs the resource continuity and response-level fault coverage required by the workflow under test.
How can you do integration testing against stateful APIs? A decision framework
For unfinished APIs, frontend development, and individual endpoint behavior, spec-driven stubs provide fast setup without unnecessary state machinery. When known call sequences stay the same, record-replay uses actual traffic to test for regressions. A different tool is needed when new inputs or sequences must give new results, because a recording has no live resource model from which to work out those results.
For multi-step integrations, the minimum requirement is full stateful simulation when IDs chain between calls, resources change status, or webhooks complete the flow. This applies to payment integrations, identity flows, and other APIs whose next response depends on prior operations. Pact adds a separate check when teams on either side of an API boundary deploy on their own. Vendor sandboxes then give teams a final way to test behavior that the local model does not reproduce.
Production resilience requires fault injection as well. Toxiproxy, Mountebank, or built-in simulator fault modes can supply coverage for retries, rate limits, and degraded upstream behavior, depending on the required fault layer. For AI agent development and RL environments, the selection criteria also include determinism, horizontal scalability, and offline operation. The test environment must preserve the consequences of earlier actions while exposing the failures that later actions must handle.


