Please make a public generator for testify mocks akin to https://github.com/matryer/moq

Open
#728 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
go
Domain
testing-qa

Research direction

No repository file or test is named. Start by comparing testify's mock API with the moq generator and the MyInterface example; done means a public generator can turn an interface into a testify mock with configurable call counts and return values.

Written by the indexing model from the issue text.

Description

https://github.com/matryer/moq generates a mock from an interface which, though nice, isn't as rich a mocking language as testify (ability to just say how many times, or return what as part of test).

It would be great if testify could provide a means of generating, for instance, from:

type MyInterface interface {
  DoSomething(int) (int, error)
}

this:

type MyInterfaceMock struct {
  mock.Mock
}

func (m *MyInterfaceMock) DoSomething(in1 int) (int, error) {
    replyArgs := m.Called(in1)
    return replyArgs.Int(0), replyArgs.Error(1)
}
Dominant language
Go
Stars
26.2k
Forks
1.9k
Avg merge
2d 4h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stretchr/testify

All issues in stretchr/testify

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.