0
0
Postmantesting~3 mins

Mock vs stub comparison in Postman - When to Use Which

Choose your learning style9 modes available
The Big Idea

What if you could test your app perfectly without waiting for a real server to respond?

The Scenario

Imagine testing an app that talks to a slow or incomplete server. You try to check if your app works, but the server is down or returns unexpected data. You wait and wait, or guess what might happen next.

The Problem

Manually testing with a real server is slow and unreliable. You can't control the server's responses easily, so tests break often. It's like calling a friend who never answers or gives confusing replies.

The Solution

Mocks and stubs let you pretend the server is there and behaves exactly how you want. You create fake responses to test your app quickly and safely, without waiting or guessing.

Before vs After
Before
Send request to real server and wait for response
Check if response is correct
After
Use stub to return fixed response
Use mock to check if request was made correctly
What It Enables

With mocks and stubs, you can test your app anytime, control all responses, and catch bugs early without relying on real servers.

Real Life Example

When building a shopping app, you use stubs to fake product data and mocks to verify your app asks for the right products, even if the real product server is offline.

Key Takeaways

Manual testing with real servers is slow and unreliable.

Stubs provide fake data to test app behavior.

Mocks verify interactions between app and server.