Golang / GoLang System Architecture and Testing Interview Questions
What is mutation testing and how does it evaluate test suite quality beyond coverage?
Mutation testing evaluates whether your tests actually catch bugs. It automatically introduces small changes (mutations) to the source code — like changing > to >= — and checks if at least one test fails. Tests that don't catch any mutation are weak.
// The function under test func isEligible(age int, hasLicense bool) bool { return age >= 18 && hasLicense } // Weak test â 100% coverage but misses mutations func TestIsEligible_Weak(t *testing.T) { if !isEligible(20, true) { t.Error("expected eligible") } if isEligible(15, true) { t.Error("expected ineligible") } } // Mutation: change age >= 18 to age > 18 // isEligible(18, true) should return true, but weak test doesn't check 18 // â mutation SURVIVES â test is weak at the boundary // Strong test â catches boundary mutations func TestIsEligible_Strong(t *testing.T) { tests := []struct { age int license bool want bool }{ {20, true, true}, // clearly eligible {17, true, false}, // underage {18, true, true}, // boundary: exactly eligible {18, false, false}, // boundary: no license {19, false, false}, // old enough but no license {0, false, false}, // both missing } for _, tt := range tests { t.Run(fmt.Sprintf("age=%d,license=%v", tt.age, tt.license), func(t *testing.T) { if got := isEligible(tt.age, tt.license); got != tt.want { t.Errorf("isEligible(%d, %v) = %v, want %v", tt.age, tt.license, got, tt.want) } }) } } // Go mutation testing tools: // - go-mutesting (zimmski/go-mutesting) // - gremlins (singularity-code/gremlins)
More Related questions...