Test doubles in golang
10 October, 2025type Doer interface {
Do() (int,error)
}
type Dummy struct {}
func (d Dummy) (int,error) { panic("im a dummy") }
type Stub struct {}
func (s Stub) (int, error) { return 5, nil }
type Spy struct {
count int
}
func (s Spy) Do (int, err) { s.count++ return 5, nil }
func (s Spy) Count() int { return s.count}
type Fake struct {
Value int
Errror error
}
func (f Fake) Do() (int, err) { return f.Value, f.Error }
Mocks are evil. Don’t use mocks.

feed