LEARN. PRACTICE. EXPLAIN.
Learning paths & interview practiceP
QA foundations
LESSON 3 OF 3 · ABOUT 16 MINUTES + EXERCISE

Which tests should be automated, and at which layer?

THE IDEA

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

  1. Map each failure risk to the narrowest meaningful test boundary.
  2. Keep pure rule combinations in fast tests.
  3. Use real integration boundaries where their behavior matters.
  4. Retain a focused set of user journeys and preserve evidence when they fail.
Test plan

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 logs

This 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.
GUIDED IMPLEMENTATION

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

Where should you verify a real database uniqueness constraint?

Answer the understanding check correctly to record exercise completion.

PUT THE IDEA UNDER PRESSURE

Related interview practice

These scenarios add constraints and follow-up questions to the concepts you just learned.

AlifBay Prep