Problem in Unit Testing using gomock

I want to mock GetAd in this file but I get this error invalid memory address or nil pointer dereference [recovered] because GetAd func is called where there is http req instead it should give mocked response. Any suggesstion?
Note: mockgen is used for building mock from interfaces, gomock is used for mocking

Main File:

type BroswerAdHandler struct {
	CustomerKey      string
	SiteID           string
	BrowserAdUsecase domain.BrowserAdUsecase

func (h BroswerAdHandler) GetBrowserAd(c echo.Context) error {
result, err := h.BrowserAdUsecase.GetAd(queryParam)
	if err != nil {
		c.JSON(http.StatusInternalServerError, echo.Map{"errorCode": "APIError", "description": 

	return c.JSON(http.StatusOK, result)

The Test File:

func TestGetBrowserAd(t *testing.T) {
var mockRespose domain.Result
err := faker.FakeData(&mockRespose)
assert.NoError(t, err)

controller := gomock.NewController(t)
defer controller.Finish()

browserAsUsecase := mock_domain.NewMockBrowserAdUsecase(controller)
browserAsUsecase.EXPECT().GetAd(gomock.Any()).Return(mockRespose, nil)

e := echo.New()
req, err := http.NewRequest(http.MethodGet, "/browserAdCampaigns?deviceId=123&appVersion=123&sdkVersion=123&deviceType=android&deviceUserAgent=kjabjsd&advertisingId=jabsd", strings.NewReader(""))
assert.NoError(t, err)

rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

a := browserAdHttp.BroswerAdHandler{CustomerKey: "someKey", SiteID: "someID", BrowserAdUsecase: usecase.BrowserAdUsecase{URL: ""}}
err = a.GetBrowserAd(c)

if err != nil {


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.