Add command to autogenerate mocks from interfaces

Open
#273 14 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
go

Research direction

Start by reviewing the existing testify mock implementation and the approaches used by mockery and goautocomplete. Compare them against the listed requirements, including composed interfaces, interfaces from other packages, go generate simplicity, configurable defaults, and generated documentation. Done means an agreed implementation proposal that addresses these requirements and preserves backwards compatibility.

Written by the indexing model from the issue text.

Description

enhancement help wanted mockery

The best way to use mock is with a program that will automatically generate the code for the mocks based on the interfaces.

mockery pioneered this approach but has some current limitations such as being unable to generate mocks from interfaces from other packages and incomplete mocks from composed interfaces.

goautocomplete addresses these issues but lacks documentation and reviewing the default behaviour to have less verbose go generate declarations.

Whichever implementation we use as a base, requirements would be:

  • Backwards compatibility once released with testify
  • Support for composed interfaces
  • Hability to generate mocks from the stdlib and other packages
  • Simplicity of use with go generate
  • Default arguments generating mocks follow conventions + arguments to override defaults
  • Generated mocks should have documentation for team mates who don't know much about mock
  • Quick way for packages to generate a package with mocks for their exported interfaces

Will follow up with an initial proposal

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.