# agiledragon/gomonkey

gomonkey is a library to make monkey patching in unit tests easy

Repository: https://github.com/agiledragon/gomonkey
Canonical: https://ross.abutalabs.com/products/gomonkey
Language: Go
License: MIT
License Family: permissive
Topics: gomonkey, patch, function, member-method, global-variable, function-variable, sequence, interface, private-method
Last push: 2026-08-02T14:29:50+00:00

## Health v2 (maintenance only)
Score: 85/100 (v2, computed 2026-09-02T17:46:02.011165+00:00)
- activity 95, release rhythm 64, longevity 100
- inputs: {"age_days": 2940, "days_push": 31, "days_rel": 31, "gap_med": 202, "n_releases_24m": 4}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 2262, forks 191 (observed 2026-08-28T04:06:31.836750+00:00)

## What it is
gomonkey is a Go library that makes monkey patching in unit tests easy, allowing functions, member methods, interfaces, function variables, and global variables to be replaced at runtime. It supports sequential patches for repeated calls and works across amd64, arm64, 386, loong64, and riscv64 architectures.

## Use cases
- mock functions in go unit tests
- patch private methods during testing
- stub interface method calls in tests
- replace global variables in test code
- mock a function to return different values on successive calls
- patch member methods without dependency injection

## When to choose
- you need to patch unexported/private functions or methods in Go tests
- you cannot refactor code to use interfaces or dependency injection
- you need a function to return different values on successive calls
- you want to stub external dependencies without changing production code

## When to avoid
- you need thread-safe patching while other goroutines call the patched function
- you cannot disable compiler inlining with -gcflags=all=-l
- you want portable, idiomatic mocking via interfaces instead of runtime patching
- your target platform or architecture is unsupported

## Facets
- artifact type: library
- maturity: active
- function: testing, mocking
- domain: testing, developer-tools
- platform: windows, go
- tags: monkey-patching, unit-testing, go, test-doubles, runtime-patching, linux, macos

## Member repositories
- agiledragon/gomonkey (main) score 85

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:06:31.836750+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T02:42:30.998720+00:00, confidence not recorded.
  - readme: https://github.com/agiledragon/gomonkey (fetched 2026-08-28T04:06:31.836750+00:00, sha c3088c10091b)
- Data as of 2026-08-30T08:39:29.467469+00:00.
