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)
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
