# vektra/mockery

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/vektra-mockery).**

7,141 stars · 454 forks · Go · BSD-3-Clause

## Links

- GitHub: https://github.com/vektra/mockery
- Homepage: https://vektra.github.io/mockery/
- awesome-repositories: https://awesome-repositories.com/repository/vektra-mockery.md

## Topics

`generation` `generator` `go` `golang` `mock` `mockgen` `mocking` `mocks` `stretchr` `testify` `testing`

## Description

Mockery is a code generation tool that produces mock implementations from Go interfaces, designed to simplify unit testing by automating the creation of test doubles. It parses Go source files using abstract syntax tree analysis to extract interface method signatures, then generates complete mock struct types that implement those interfaces with configurable function fields for test injection.

The tool distinguishes itself through its configuration and customization capabilities. Rather than embedding directives in source code annotations, Mockery reads generation settings from a YAML configuration file, centralizing mock generation parameters. It also supports custom Go text/templates to control the structure and behavior of generated mock code, allowing teams to shape output to match their testing patterns and conventions.

Mockery covers the full workflow of interface-to-mock generation, from parsing interface definitions to producing ready-to-use mock source files. Its template-driven output and YAML-based configuration provide a flexible foundation for integrating mock generation into existing Go testing workflows.

## Tags

### Testing & Quality Assurance

- [Go Interface](https://awesome-repositories.com/f/testing-quality-assurance/mocking-frameworks/go-interface.md) — A framework that creates mock objects from Go interface definitions to simplify test setup and verification.
- [Struct-Based](https://awesome-repositories.com/f/testing-quality-assurance/dependency-mocking/delegate-mocks/struct-based.md) — Creates struct types that implement interfaces by delegating to configurable function fields for test injection.
- [Interface-to-Mock Generators](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/dependency-mocking/automated-mock-generation/interface-to-mock-generators.md) — Generates mock objects from Go interfaces to remove manual boilerplate needed for testing with mock frameworks. ([source](https://vektra.github.io/mockery/))

### Programming Languages & Runtimes

- [Method Signature Analyzers](https://awesome-repositories.com/f/programming-languages-runtimes/function-signatures/method-signature-analyzers.md) — Analyzes parameter and return types of interface methods to generate matching mock function signatures.
- [Mock Code Generators](https://awesome-repositories.com/f/programming-languages-runtimes/go-code-generators/mock-code-generators.md) — Automatically generates mock implementations from Go interfaces for use in unit testing and dependency injection.
- [Interface Mock Generators](https://awesome-repositories.com/f/programming-languages-runtimes/go-mocking-libraries/interface-mock-generators.md) — Generates mock implementations from Go interfaces to replace real dependencies in unit tests.

### Software Engineering & Architecture

- [Interface AST Parsers](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-parsing/interface-ast-parsers.md) — Parses Go interface definitions into ASTs to extract method signatures for mock generation.
- [Compile-Time Code Generation](https://awesome-repositories.com/f/software-engineering-architecture/compile-time-code-generation.md) — Generates mock source files at build time by parsing Go interfaces and producing implementation code.
- [Test Service Injections](https://awesome-repositories.com/f/software-engineering-architecture/integration-extensibility/dependency-injection/type-safe-context-injections/test-data-injections/test-service-injections.md) — Creates mock objects that can be injected into Go code to isolate and test specific components.
- [YAML Configuration Files](https://awesome-repositories.com/f/software-engineering-architecture/application-lifecycle-management/configuration-management/configuration-formats-and-schemas/yaml-configuration-files.md) — Reads mock generation settings from a YAML file to centralize configuration instead of using source code annotations.
- [Mock Generation Configuration Files](https://awesome-repositories.com/f/software-engineering-architecture/application-lifecycle-management/configuration-management/configuration-formats-and-schemas/yaml-configuration-files/mock-generation-configuration-files.md) — Configures mock generation settings in a YAML file instead of scattering directives across source code. ([source](https://vektra.github.io/mockery/))
- [Mock Generator Configurations](https://awesome-repositories.com/f/software-engineering-architecture/application-lifecycle-management/configuration-management/configuration-formats-and-schemas/yaml-configuration-files/mock-generator-configurations.md) — Reads configuration from YAML files instead of inline source code directives for mock generation.

### Artificial Intelligence & ML

- [Code Generation Templates](https://awesome-repositories.com/f/artificial-intelligence-ml/output-templating-engines/template-driven-output-generators/code-generation-templates.md) — Uses Go text/template files to control the structure and behavior of generated mock code.

### Data & Databases

- [Template-Based Code Customizers](https://awesome-repositories.com/f/data-databases/custom-data-types/custom-data-type-providers/code-generators/template-based-code-customizers.md) — Uses custom templates and template data to control the structure and behavior of generated mocks.
- [Mock Generation Template Customizers](https://awesome-repositories.com/f/data-databases/custom-data-types/custom-data-type-providers/code-generators/template-based-code-customizers/mock-generation-template-customizers.md) — Supplies custom templates and data to shape the structure and behavior of generated mock code.

### User Interface & Experience

- [Generation Templates](https://awesome-repositories.com/f/user-interface-experience/layout-utilities/presentation-engines/template-engines/configuration-and-integration/custom-template-integrations/generation-templates.md) — Customizes generated mock code by supplying templates and template data to control its structure and behavior. ([source](https://vektra.github.io/mockery/))

### Web Development

- [Mock Generation Configurations](https://awesome-repositories.com/f/web-development/single-page-applications/single-file-distributions/json-driven-configurations/yaml-driven-configurations/mock-generation-configurations.md) — Configures mock generation settings and templates through a YAML file instead of inline source annotations.

### Part of an Awesome List

- [Frameworks and Libraries](https://awesome-repositories.com/f/awesome-lists/devtools/frameworks-and-libraries.md) — An automatic mock code generator for testing.
- [Testing Frameworks](https://awesome-repositories.com/f/awesome-lists/devtools/testing-frameworks.md) — Generates mock code for interfaces.
