Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Error - Mock method with int and string parameters #19

@alvalea

Description

@alvalea

Mocking a method with int and string parameters generates a mock that does not expect those types. However, if both parameters are of type string, it works properly.

output
alem@alem-vm:~/Workspace/go/src/alem/test1$ go test lib_test.go                                                                                                         
--- FAIL: TestMyThing (0.00s)
        controller.go:113: no matching expected call: *mock_mypackage.MockMyInterface.SomeMethod([1 second])
        controller.go:158: missing call(s) to *mock_mypackage.MockMyInterface.SomeMethod(is equal to 1, is equal to second)
        controller.go:165: aborting test due to missing call(s)
FAIL
FAIL    command-line-arguments  0.002s
lib.go
package mypackage

type MyInterface interface {
  SomeMethod(x uint64, y string)
}
lib_test.go
package mypackage

import (
  "testing"
  "alem/test1/lib_mock"
  "github.com/golang/mock/gomock"
)

func TestMyThing(t *testing.T) {
  mockCtrl := gomock.NewController(t)
  defer mockCtrl.Finish()

  mockObj := mock_mypackage.NewMockMyInterface(mockCtrl)

  gomock.InOrder(
    mockObj.EXPECT().SomeMethod(1, "second"),
  )

  mockObj.SomeMethod(1, "second")
}
mockgen
mockgen -source=lib.go > lib_mock/lib_mock.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions