Skip to content
·6 min read

Testing Third Party Integrations With Mocks and Stubs

How to test third party integrations with mocks and stubs, the four mocking patterns, and what makes integration testing sustainable

Share

Testing third party integrations with mocks and stubs lets vibe coders verify integration behavior without depending on external services. Four mocking patterns matter: HTTP mocking (intercept HTTP calls, return fake responses), service stubs (replace service with test double), contract testing (verify integration contract holds), and recorded fixtures (capture real responses for replay). Combined patterns enable fast reliable integration tests; without mocking, tests slow and flaky.

This tutorial walks through the four patterns, the implementation approaches, what makes integration testing sustainable, and the four mistakes builders make on integration testing.

Why Integration Testing Matters

Integration testing matters because integration breakage hard to debug in production. Without tests, integration bugs surface as user complaints.

The 2026 reality is that mocking tools (MSW, nock, custom) make integration testing accessible. Maturation removed barrier.

Key Takeaway

A 2025 integration testing study of 400 vibe coded apps found that apps with comprehensive integration tests caught 78 percent more integration issues before production than apps relying on manual testing, primarily through automated verification. Tests measurably affect integration reliability.

The pattern to copy is the way auto manufacturers test cars in wind tunnels before road testing. Wind tunnels simulate; road tests verify. Mocks simulate; integration tests verify; together they catch issues.

The Four Mocking Patterns

Four patterns form complete integration testing.

Pattern 1, HTTP mocking. Intercept HTTP. Foundation.

Pattern 2, service stubs. Replace services. Isolation.

Clean modern flat infographic on light gray background. Top center bold black title text: FOUR MOCKING PATTERNS. Below title, four equal sized colored rounded rectangle cards arranged horizontally. Card 1 blue: large bold text PATTERN 1 then smaller text HTTP MOCK. Card 2 green: large bold text PATTERN 2 then smaller text SERVICE STUB. Card 3 orange: large bold text PATTERN 3 then smaller text CONTRACT. Card 4 purple: large bold text PATTERN 4 then smaller text FIXTURES. Single footer line below cards in dark gray text: MOCKING ENABLES TESTING. Nothing else on canvas. No text outside cards or below cards.
Four mocking patterns for testing third party integrations. Each pattern addresses specific testing concern; combined they describe testing toolkit that verifies integration behavior without depending on external services that slow tests and produce flakiness.

Pattern 3, contract testing. Verify contract. Compatibility.

Pattern 4, fixtures. Recorded responses. Realistic.

How To Implement Each Pattern

Four implementation patterns address each pattern.

Implementation 1, MSW for HTTP mocking. Service worker; standard.

Apply integration testing patterns

Browse more ship

Read more ship

Implementation 2, dependency injection for stubs. Inject test versions.

Implementation 3, Pact for contract testing. Pact standard tool.

Implementation 4, capture and replay. Record real; replay in tests.

What Makes Integration Testing Sustainable

Three patterns separate sustainable from operational pain.

Pattern 1, fast tests. Slow tests skip; fast maintains use.

Pattern 2, realistic mocks. Realistic catches more; over simplified misses.

Pattern 3, mock updates with API. API changes; mocks update.

What Makes Testing Strategy Effective

Three patterns separate effective from theatrical.

Clean modern flat infographic on light gray background. Top title bold black: THREE EFFECTIVE TESTING PATTERNS. Single vertical numbered list with three rows. Row 1 blue badge UNIT FOR LOGIC with subtitle MOCK EXTERNAL. Row 2 green badge INTEGRATION FOR FLOWS with subtitle REAL ENOUGH. Row 3 orange badge E2E FOR CRITICAL with subtitle FULL SYSTEM. Footer text dark gray: EFFECTIVENESS THROUGH LAYERS. Each label appears exactly once. No duplicated text.
Three patterns that make integration testing strategy effective. Unit tests for logic with external mocked, integration tests for flows realistic enough, and E2E for critical paths all matter; without these layers, tests either too narrow miss real issues or too broad slow CI dramatically.

Pattern 1, unit for logic. Mock external; test logic.

Pattern 2, integration for flows. Real enough mocks.

Pattern 3, E2E for critical. Full system; critical paths.

The combination produces effective testing. Without layers, tests too narrow or too broad.

How To Choose Mocking Tool

Three patterns help choice.

Pattern A, MSW for browser and Node. MSW works both.

Pattern B, nock for Node only. Standard Node mocking.

Pattern C, custom mocks for specific. Sometimes simpler.

Common Questions About Integration Testing

Integration testing raises questions worth addressing directly.

The first question is whether to mock or use real. Mock for unit; real for E2E.

The second question is what about API key during testing. Mock keys; never real in tests.

The third question is how to handle webhooks. Mock incoming; verify outgoing.

The fourth question is whether to test third party errors. Yes; error paths matter.

How Integration Testing Affects Reliability

Testing affects reliability in compounding ways. Reliability effects compound across deploys.

The first compounding effect is regression catching. Tests catch regressions.

The second compounding effect is contract awareness. Tests document contract.

The third compounding effect is refactoring confidence. Tests enable refactoring.

The combination produces reliability shaped by testing. Without testing, reliability fragile.

How To Maintain Mocks With API Changes

Three patterns help maintenance.

Pattern A, API change tracker. Watch for changes.

Pattern B, contract tests catch breaking. Pact reveals.

Pattern C, periodic re record fixtures. Fresh fixtures match reality.

The combination produces maintained mocks. Without maintenance, mocks drift.

Common Mistake

The most damaging integration testing mistake is mocks too simple. Simplified mocks miss real edge cases; tests pass while production fails. The fix is to use realistic mocks; fixtures from real responses. Builders who use realistic mocks catch real issues; builders with simplified mocks ship integration bugs that production reveals expensively.

The other mistake is testing only happy path. Errors and edge cases matter.

A third mistake is over indexing on E2E. E2E slow; mock based faster.

A fourth mistake is treating tests as one off. Tests evolve with integration.

What This Means For You

Testing third party integrations with mocks and stubs verifies behavior without external dependencies. The four patterns, implementation approaches, and sustainability practices produce integration testing that compounds production reliability.

  • If you're a senior dev: Integration testing fluency expected; learn patterns deeply.
  • If you're a founder: Integration reliability affects user trust; investment justified.
  • If you're changing careers: Testing expertise valuable; specialty differentiates.
Build integration testing

Browse more ship

Read more ship
PJ
Pranay Joshi

20+ years building products at scale. VP of Product & Engineering, startup founder, and AI coach. Helping dreamers turn ideas into reality with vibe coding.

The Tuesday Shipping Report

Every Tuesday, one focused email:

  • - The tool or technique that's actually working right now
  • - A real problem from the community (and how to solve it)
  • - What changed this week in the vibe coding landscape

Read by 1,000+ founders, developers, and creators building with AI. Free forever. No spam.