StableMock Logo

StableMock

Auto-record them APIs to WireMock stubs. Zero config.

Stop hand-writing mocks for flaky external APIs. StableMock records real HTTP calls during your tests, turns them into WireMock stubs, and replays them reliably — even when request data changes.

Built for JUnit 5. Works offline. Free & open source.

Where your tests find their rest.

Cowboy looking at logo

Why StableMock?

StableMock is a JUnit 5 extension that automatically records third-party API calls and replays them using WireMock — without manual setup, Docker, or brittle matchers.

Perfect for mocking external/third-party APIs • Fast, lightweight HTTP mocking without Docker overhead • Tests with dynamic request data that need intelligent pattern matching

🤠

Zero-Config Recording

Add @U to your test and StableMock automatically records and replays all external HTTP calls — no config files, no setup.

🪢

Smart Pattern Matching

Handles timestamps, IDs, and tokens with ignore patterns like json:timestamp or xml://MessageID. Auto-detects dynamic fields.

🌵

Native JUnit 5

Built right into JUnit 5. No manual lifecycle management needed. Parallel execution? Each test gets its own isolated WireMock instance.

🐂

GraphQL & REST Support

Handles GraphQL (auto-detected), REST, SOAP, and XML. Even nested fields like json:user.session.token work seamlessly. Supports namespaced XML too.

🌾

100% Free & Open Source

MIT licensed. No paid tiers, no cloud dependencies. Free forever. Perfect for mocking external APIs you don't control.

🐎

Offline Testing

Perfect for CI/CD pipelines. Runs tests offline with recorded mocks. No waiting on real APIs or worrying about changes. Record once, replay forever.

How StableMock Works

Auto-mocking for your tests! StableMock automatically records and replays HTTP calls to external APIs.

Zero-config recording • Smart pattern matching • Free forever

How StableMock Works - Auto-Mocking for Your Tests

Get Started in Seconds

This test runs twice automatically:

  1. 1. First run: Records real API responses and identifies changing fields (timestamps, IDs, etc.)
  2. 2. Second run: Replays responses offline using WireMock with auto-generated ignore patterns for dynamic fields

StableMock compares the two runs to detect which fields change between executions, then automatically creates ignore patterns so your tests remain stable even when request data varies.

@U(urls = { "https://api1.com", "https://api2.com" },
   properties = { "app.api1.url", "app.api2.url" })
@SpringBootTest
class MyTest extends BaseStableMockTest {
    @DynamicPropertySource
    static void configureProperties(DynamicPropertyRegistry registry) {
        autoRegisterProperties(registry, MyTest.class);
    }
    
    @Test
    public void myTest() {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("http://localhost:8080/api/users"))
            .GET()
            .build();
        HttpResponse<String> response = client.send(
            request, HttpResponse.BodyHandlers.ofString()
        );
        assertEquals(200, response.statusCode());
    }
}

That's it. No configuration. No setup. Just works. Even with everchanging request attributes.

Developer Guides

Learn how to master integration testing in Spring Boot.

Stop Rewriting Mocks By Hand, Son

Record once. Test offline forever.

Join developers who've made the switch. Free forever. No credit card required.

🌾 MIT License | 🚀 Open Source | 💯 Free Forever