Mutation testing

변이 테스트

Deliberately alter code to see whether existing tests detect the fault.

···
html
<div class="stage"><div class="title">MUTATION TEST</div><div class="canvas"><div class="code mono">age <b id="operator">≥</b> 18</div><div class="checks"><span id="check17">17: FAIL</span><span id="check18">18: PASS</span><span id="check19">19: PASS</span></div><div class="verdict" id="verdict">original passes</div></div></div>
css
.stage{width:min(94vw,820px);height:min(88vh,330px);box-sizing:border-box;padding:clamp(9px,2.4vmin,18px);border:1px solid var(--line);border-radius:13px;background:var(--surface);display:flex;flex-direction:column;gap:clamp(7px,2vmin,14px);font:600 clamp(12px,2.5vmin,16px)/1.28 "Pretendard Variable",Pretendard,-apple-system,BlinkMacSystemFont,"Apple SD Gothic Neo",sans-serif;color:var(--fg);overflow:hidden}.title{color:var(--accent);letter-spacing:.035em;flex:none}.canvas{position:relative;flex:1;min-height:0;display:flex;align-items:center;justify-content:center}.muted{color:var(--muted)}.mono{font-family:ui-monospace,SFMono-Regular,monospace}.box{border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:clamp(5px,1.4vmin,12px);text-align:center}.active{border-color:var(--accent)!important;color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 12%,var(--surface))!important}.canvas{flex-direction:column;gap:clamp(10px,3vmin,24px)}.code{font-size:clamp(18px,5vmin,30px);border:1px solid var(--line);padding:8px 18px;border-radius:8px}.code b{color:var(--accent)}.checks{display:flex;gap:5px;flex-wrap:wrap;justify-content:center}.checks span{border:1px solid var(--line);padding:5px;border-radius:5px}.checks .caught{border-color:var(--accent-3);color:var(--accent-3)}.verdict{color:var(--accent)}
js
let mutated=false;function flip(){mutated=!mutated;document.getElementById('operator').textContent=mutated?'>':'≥';document.getElementById('check18').textContent=mutated?'18: FAIL':'18: PASS';document.getElementById('check18').classList.toggle('caught',mutated);document.getElementById('verdict').textContent=mutated?'mutant killed by age 18':'original passes'}flip();setInterval(flip,1500)

Mutation testing makes small code changes, such as swapping a comparison operator, and runs the tests again. A failure kills the mutant; a pass may reveal a missing assertion.

The demo changes ≥ to > and shows a boundary test detecting it. A surviving mutant is not always a real defect, so distinguish equivalent mutations from meaningful gaps.

When to use

Use it to assess whether tests detect faults, beyond simply counting tests.

Open as page ↗