package main
import (
"github.com/golang/mock/gomock"
"testing"
)
type Talker interface {
talk() string
}
type Person struct {
moth *Talker
}
func (p *Person) speak() string {
return (*p.moth).talk()
}
func TestPerson(t *testing.T) {
ctrl := gomock.NewController(t)
mockTalker := NewMockTalker(ctl)
person := Person{moth: mockTalker}
}
假设我已经使用 mockgen 为 Talker 界面创建了一个模拟。
我在创建时遇到错误Person{moth: mockTalker}
。我无法通过mockTalker
。