I am using gomock to create mock objects for unit testing. The following gives the mock object a method called GetQuestionById and tells the mock controller to expect the method to be called with argument 1:
gw.EXPECT().GetQuestionById(1)
But how do I specify that the mocked method should return a particular value?
When you call gw.EXPECT().GetQuestionById(1)
, it ends up calling the method RecordCall
on the mock controller. RecordCall
returns a Call
, and Call
has a method called Return
that does exactly what you want:
gw.EXPECT().GetQuestionById(1).Return(Question{1, "Foo"})