Recall Before reading on: predict whether this mutant survives
Code: def max2(a,b): return a if a > b else b. Test: assert max2(3, 1) == 3.
Mutant: a > b → a < b. Survive or killed?
Answer: With max2(3,1), mutant returns b = 1 ≠ 3 → test fails → KILLED. But mutant a > b → a >= b would survive this test (need a == b case, e.g. max2(5,5), to kill it).
Why subtract equivalent mutants from the denominator?
They behave identically to the original, so no test can ever kill them; counting them would unfairly lower the score.
What's the key limitation of code coverage that mutation testing fixes?
Coverage proves a line ran, not that any assertion would catch a bug in it.
What is an equivalent mutant?
A syntactic change that produces identical behaviour to the original program; it can never be killed.
A surviving (non-equivalent) mutant tells you to do what?
Add or strengthen a test — not fix the production code.
Give a mutation operator example
Swap > → >=, + → -, True → False, or delete a statement.
Recall Feynman: explain to a 12-year-old
Imagine you built a smoke alarm and you want to know if it really works. You don't just look at it — you light a tiny match under it to see if it screams. Mutation testing does that to your tests: it secretly breaks your program in small ways (lights little "bug matches") and watches whether your tests scream (fail). If your tests stay silent while the program is broken, your tests are bad smoke alarms and need fixing.
Dekho, mutation testing ka idea bahut simple hai. Tum code likhte ho, tests likhte ho, aur tests pass ho jaate hain — par sawaal yeh hai ki tumhare tests sach mein bugs pakadte hain ya bas dikhaawa hai? Code coverage sirf yeh batata hai ki line "chali" thi, par yeh nahi batata ki agar line galat hoti to koi test fail hota ya nahi. Yahin par mutation testing kaam aata hai.
Mutation testing kya karta hai? Woh tumhare code mein chhote-chhote jaan-boojh kar bugs daalta hai — jaise > ko >= bana dena, ya + ko -. Har aisa changed version ek mutant kehlata hai. Phir woh tumhare tests chalata hai. Agar koi test fail ho gaya, matlab tumne bug pakad liya — mutant killed (badhiya!). Agar saare tests phir bhi pass ho gaye, matlab tumhara test suite us bug ko miss kar gaya — mutant survived (yeh ek warning hai ki test kamzor hai).
Score nikaalne ka formula: K/(M−E), yaani killed mutants divide by (total mutants minus equivalent mutants). Equivalent mutants woh hote hain jo dikhne mein alag hain par behaviour bilkul same hai — unhe koi test maar hi nahi sakta, isliye unhe denominator se hata dete hain. 100% score milna mushkil hota hai, isliye 80/20 rule lagao: critical logic par focus karo.
Yaad rakho — agar mutant survive karta hai, to iska matlab tumhara production code kharab hai aisa nahi; iska matlab tumhe ek naya ya behtar test likhna hai. Mutation testing tumhare tests ko grade karta hai, code ko nahi. Isiliye yeh real software engineering mein quality ka sabse strong proof hai.