// Code generated by mockery v1.0.0. DO NOT EDIT.packagemocksimportmock"github.com/stretchr/testify/mock"// Stringer is an autogenerated mock type for the Stringer typetypeStringerstruct{mock.Mock}// Name provides a mock function with given fields: hifunc(_m*Stringer)Name(histring)string{ret:=_m.Called(hi)varr0stringifrf,ok:=ret.Get(0).(func(string)string);ok{r0=rf(hi)}else{r0=ret.Get(0).(string)}returnr0}
Write test with mock data
string_test.go
1234567891011121314151617181920
packagemainimport("testing""github.com/mgleon08/mock/mocks""github.com/stretchr/testify/assert""github.com/stretchr/testify/mock")funcTest_SayName(t*testing.T){// mock interfacemockStringer:=&mocks.Stringer{}// mock function and expected return you want datamockStringer.On("Name",mock.Anything).Return("hi, test")t.Run("test",func(t*testing.T){assert.Equal(t,"hi, test",SayName(mockStringer))})}