golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.3k stars 610 forks source link

how to mockgen embedded interface #521

Closed relxet closed 3 years ago

relxet commented 3 years ago

File foo.go

type Foo interface {
    Bar
}

File bar.go

type Bar interface {
    Open()
    Write()
}

How to mockgen the file foo.go?

codyoss commented 3 years ago

Hey,

You can use reflect mode to do this easily as it will load the whole package(assumes module example.com/gm521 and code in package gm521):

mockgen -destination=foo_mock_test.go -package=gm521 example.com/gm521 Foo