4.5.13Software Engineering

Testing — unit, integration, system, acceptance, smoke, regression

2,192 words10 min readdifficulty · medium

The Test Pyramid (the 80/20 of testing)

Figure — Testing — unit, integration, system, acceptance, smoke, regression

The six types — WHAT / WHY / HOW


Worked examples


Two key "numbers" worth deriving


Flashcards

What does a unit test isolate and how?
The smallest piece (function/class) by replacing dependencies with mocks/stubs.
Integration test — what does it specifically check?
That two or more units work together correctly at their seam/interface (often with real collaborators like a DB).
System test answers which V&V question?
Verification — "are we building the product right?" (meets spec, full app black-box).
Acceptance test answers which V&V question?
Validation — "are we building the right product?" (meets user/business need; UAT).
Purpose of a smoke test?
A tiny fast check that the build isn't fundamentally broken; run first to gate the full suite.
Purpose of a regression test?
Re-run existing tests after a change to ensure previously-working features still work.
Why is the test pyramid shaped wide at the bottom?
Unit tests are fast, cheap, deterministic and pinpoint faults; high-level tests are slow/flaky/vague — so write many cheap ones.
Cost of a bug escaping n stages (formula)?
Cost=ckn\text{Cost}=c\cdot k^n, roughly 10× per stage.
Why not mock the database in a DB integration test?
You'd be testing the mock, not the real seam — it degenerates into a unit test.
Suite trust probability for n independent tests each reliable p?
P=pnP=p^n — flaky tests compound fast.

Recall Feynman: explain it to a 12-year-old

Imagine you build a LEGO spaceship. Unit test: you check each LEGO brick isn't cracked. Integration test: you snap two bricks together and tug — do they hold? System test: you fly the whole spaceship around the room — does it work? Acceptance test: you show your friend who said "I want a red spaceship" — is it actually red like they wanted? Smoke test: before anything, you just check it doesn't fall apart the second you pick it up. Regression test: after adding a new wing, you re-check the old wing didn't pop off. Checking each brick is cheap; finding a crack only after the spaceship crashes is expensive — that's why we check small things first and often.


Connections

  • Test-Driven Development (TDD) — write the failing unit test first.
  • Mocks Stubs and Fakes — the tools that make unit isolation possible.
  • Continuous Integration — where smoke + regression run automatically per commit.
  • Verification and Validation — the V&V framing of system vs acceptance.
  • Code Coverage — measuring how much your tests exercise the code.
  • Behaviour-Driven Development (BDD) — Given/When/Then for acceptance tests.
  • Defect Cost of Delay — the cknc\cdot k^n economics behind testing early.

Concept Map

many, cheap, fast

fewer

very few, slow

isolates via mocks/stubs

catches

combine units

assemble app

works correctly?

right thing? UAT/BDD

quick check before

triggers

re-runs

motivates catching early

Test Pyramid

Unit test

Integration test

System test

Faults at seams

Acceptance test

Customer requirements

Smoke test

New change

Regression test

Bug cost ~10x per stage

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, software ek tower ki tarah hota hai — chhote chhote parts jud ke poori app banti hai. Testing ka matlab hai har stage pe check karna ki cheez sahi chal rahi hai ya nahi. Unit test sabse chhota part (ek function) ko akele test karta hai, dependencies ko mock kar ke — taaki agar fail ho to pata chale ki yahi function galat hai. Integration test do parts ko jod ke dekhta hai (jaise tumhara code + real database) — kyunki dono alag-alag sahi hote hue bhi seam pe break ho sakte hain.

System test poori app ko ek black box ki tarah test karta hai — "kya product sahi se kaam karta hai?" (yeh Verification hai). Acceptance test poochta hai "kya yeh wahi product hai jo customer ne maanga tha?" (yeh Validation hai, UAT). Yeh dono confuse mat karna — system = theek banaya?, acceptance = sahi cheez banayi?

Smoke test ek chhota, fast check hai — "app on bhi ho rahi hai ya nahi?" Yeh sabse pehle chalao; agar yahi fail hua to baaki 20 minute waste mat karo. Regression test ka matlab — naya code add karne ke baad purane saare tests dobara chalao, taaki pata chale tumne galti se koi purani feature na tod di ho.

Sabse important baat: test pyramid — niche bahut saare saste fast unit tests, upar bahut kam slow system tests. Kyun? Kyunki bug agar early pakda jaaye to sasta hai, production tak pahunch gaya to lagbhag 10× har stage pe mehenga ho jaata hai (Cost = c·k^n). Isi liye 80% effort niche wale unit tests pe lagao — yahi 20% jagah hai jo maximum bugs sabse sasti me pakadti hai.

Go deeper — visual, from zero

Test yourself — Software Engineering

Connections