-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
Is your feature request related to a problem? Please describe.
A quick guide for interface mocking is needed
Describe the solution you'd like
type Fooer interface{
Foo(string) string
}
type A struct{}
func (a A) Foo(in string) string { return in }
func UseFoo(f Fooer) string {
// something
return f.Foo("")
}
func TestMockXXX(t *testing.T) {
PatchConvey("TestMockXXX", t, func() {
Mock(Fooer.Foo).Return("c").Build() // something like this is needed
So(UseFoo(A{}), ShouldEqual, "c") // assert `Fooer.Foo` is mocked
})
}
Describe alternatives you've considered
func TestMockXXX(t *testing.T) {
PatchConvey("TestMockXXX", t, func() {
MockInterface(Fooer.Foo).Return("c").Build() // something like this is needed
So(UseFoo(A{}), ShouldEqual, "c") // assert `Fooer.Foo` is mocked
})
}
Additional context
- for now
GetNestedMethod
seems to work, but not elegant. - I know I can do interface insertion, but this Mock func is just so good, I want to use it the same way.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed