What it is
Unit tests isolate small pieces of behavior, integration tests exercise collaborating components, and end-to-end tests follow a user journey through the system. Test doubles replace dependencies to control conditions, but they can disagree with the real dependency.
Why you need it
Putting every assertion in a browser test makes feedback slow and failures hard to isolate. Testing only mocked functions can miss wiring, persistence, and contract defects.
How it works
- Map each failure risk to the narrowest meaningful test boundary.
- Keep pure rule combinations in fast tests.
- Use real integration boundaries where their behavior matters.
- Retain a focused set of user journeys and preserve evidence when they fail.
Coverage for a checkout flow
Unit: tax calculation and rounding rules
Integration: unique payment-attempt key in the database
Contract: provider request and response shapes
End to end: place an order and see its confirmed status
Failure evidence: request IDs, timings, sanitized logsThis plan assigns different questions to different layers. A simulated provider can produce difficult failures, while contract checks reduce the risk of inaccurate mocks.
Good practices and why
- Wait for observable conditions rather than arbitrary sleeps.
- Use independent test data and retain first-failure evidence when retries are allowed.
Common mistakes
- Rerunning until green and discarding the original failure.
- Assuming a mocked response proves an external API integration works.
Try it yourself
Take a flaky save test and list evidence that would distinguish a product race, shared test data, and an unreliable wait.
What a successful result looks like
Your plan collects a timeline and tests a hypothesis instead of only increasing timeout values.
0 / 6000 characters · Saved on this device. Do not include passwords or private data.
Check your understanding
Answer the understanding check correctly to record exercise completion.
Related interview practice
- The test passes when you rerun it. ↗
- The test suite is slow and still misses defects. ↗
- The developer cannot reproduce your bug. ↗
These scenarios add constraints and follow-up questions to the concepts you just learned.