টেস্টিং
unit, integration, contract, E2E, load—risk-ভিত্তিক fast feedback।
Start with the production incident, then the design decision that fixes it.
চলো-র payment service-এর unit test সব সবুজ। Friday deploy-এর পর দেখা গেল invoice total ভুল—কারণ currency conversion service-এর contract বদলেছে, কিন্তু payment service-এর mock পুরোনো response দিচ্ছিল। Unit test ঠিকই পাস করেছে; integration test ছিল না।
মাহিন বলল, "test pyramid ভেঙে পড়েছে—আমরা শুধু পিরামিডের তলা মজবুত করেছি, মাঝখানে কিছু নেই।" Testing মানে coverage number নয়; বোঝা যে change-এর পর সিস্টেম আগের মতোই কাজ করবে। unit দ্রুত, integration বাস্তব, contract দুই service-এর চুক্তি, E2E user journey, load capacity—প্রতিটা আলাদা প্রশ্নের উত্তর দেয়।
Unit test। এক function/class, milliseconds, external dependency mock। Business logic, edge case, validation—এখানে। ৭০% test এখানে হওয়া উচিত, কিন্তু unit mock-কে সত্য ভেবো না।
Integration test। Real DB/Redis/queue, এক service-এর ভিতরের interaction। Migration, transaction, unique constraint, SQL—এখানে ধরা পড়ে। Container/test DB ব্যবহার করো।
Contract test। দুই service-এর request/response schema; producer/consumer একই contract test চালায়। Payment-service invoice বদলালে consumer test fail করবে—এটাই missing ছিল।
E2E। Browser/API দিয়ে user journey; ধীর, তাই কম। Booking → payment → confirmation—happy path + এক-দুই critical failure।
Load/soak test। Capacity, p95, memory leak; staging-এ realistic data। ১০k SSE-র মতো test আলাদা।
Test data আর flakiness। প্রতিটা test নিজের data বানায়/মুছে; shared fixture নয়। Flaky test quarantine, root cause; retry দিয়ে ঢেকে দিও না।
| স্তর | গতি | কী ধরে | কত |
|---|---|---|---|
| Unit | ms | logic, edge | বেশি |
| Integration | ১০০ms–s | DB, queue, SQL | মাঝারি |
| Contract | ms–s | API schema | প্রতি service |
| E2E | s–min | user journey | কম |
| Load | min | capacity | release gate |
একটা unit + integration test-এর পার্থক্য:
def test_total_with_tax():
assert invoice_total([100, 200], tax=0.05) == 315.0
# integration: real DB unique constraint
def test_double_booking(db):
db.insert_booking(ride_id="r1", seat_id="s1", rider_id="u1")
with pytest.raises(UniqueViolation):
db.insert_booking(ride_id="r1", seat_id="s1", rider_id="u2")
# load smoke: p95 under 300ms at 50 concurrent
k6 run --vus 50 --duration 60s load/booking.js
# contract: consumer verifies producer schema
pytest tests/contract/test_payment_consumer.py
Unit test DB constraint ধরে না; integration test ধরে। দুটোই দরকার—একটা আরেকটার বিকল্প নয়।
১. Risk map করো। কোন module-এ bug হলে টাকা/PII/outage? সেখানে বেশি test, কম ঝুঁকিতে কম।
২. Pyramid ঠিক করো। Logic unit, DB/queue integration, service boundary contract, critical journey E2E, release load।
৩. CI-তে fast gate। Unit+contract ৫ মিনিটে; integration/container ১৫ মিনিট; E2E/load nightly বা release।
৪. Test data isolation। প্রতিটা test unique id, cleanup; shared user/DB state নয়। Migration test fresh DB-তে।
৫. Flaky management। Quarantine, owner, deadline; retry নয়। Coverage নয়, mutation/risk-ভিত্তিক test।
invoice_total-এ currency conversion যোগ করো। প্রথমে unit test লেখো, তারপর এমন integration test লেখো যেটা ভুল currency rate ধরে। শেষে contract test-এ response schema বদলে দেখো consumer fail করে কি না। কোন স্তর bug ধরল, লিখে রাখো।
Coverage ৯০% মানে ১০% ঝুঁকি নেই—numbers নয়, risk দেখো। Production-এ canary/feature flag দিয়ে test করো; test environment production নয়। Migration test fresh DB + existing data দুইটাতেই চালাও; শুধু fresh DB-তে পাস করলে production drift ধরবে না।
See the mental model first — the animation and the steps below it say the same thing.
Concept visual
unit সেকেন্ডে চলে, e2e মিনিটে—নিচের ধাপ যত মোটা, উপরে তত কম পরীক্ষা থাকে।
Write a short design on paper or in a note, then compare it with the rubric. This is not a judge submission.
Design practice
payment unit সব green; currency contract বদলে prod ভাঙল।
One timed attempt. Solve every problem to earn the module badge.
Final checkpoint
Ready to prove this module?
Ask questions, share an approach or leave a study tip for this lesson.
Was this lesson helpful?
Your reaction helps other learners judge these notes.
0 comments
Sign in to ask a question or share an approach.
Sign in to commentNo comments yet
Be the first to ask a question or leave a study tip.
| প্রশ্ন | উত্তর |
|---|
| Logic? | unit |
| DB/SQL? | integration |
| API change? | contract |
| User journey? | E2E |
| Capacity? | load/soak |
| Flaky? | quarantine + fix |