Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gomonkey

> 编程语言
Open source

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

2.3K stars0 likes0 views
WebsiteGitHub

About

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

gomonkey

gomonkey is a library to make monkey patching in unit tests easy, and the core idea of monkey patching comes from Bouke, you can read this blogpost for an explanation on how it works.

Features

  • support a patch for a function
  • support a patch for a public member method
  • support a patch for a private member method
  • support a patch for a interface
  • support a patch for a function variable
  • support a patch for a global variable
  • support patches of a specified sequence for a function
  • support patches of a specified sequence for a member method
  • support patches of a specified sequence for a interface
  • support patches of a specified sequence for a function variable

Notes

  • gomonkey fails to patch a function or a member method if inlining is enabled, please running your tests with inlining disabled by adding the command line argument that is -gcflags=-l(below go1.10) or -gcflags=all=-l(go1.10 and above).
  • A panic may happen when a goroutine is patching a function or a member method that is visited by another goroutine at the same time. That is to say, gomonkey is not threadsafe.

Supported Platform:

  • ARCH

    • amd64
    • arm64
    • 386
    • loong64
    • riscv64
  • OS

    • Linux
    • MAC OS X
    • Windows

Installation

  • below v2.1.0, for example v2.0.2
$ go get github.com/agiledragon/[email protected]
  • v2.1.0 and above, for example v2.11.0
$ go get github.com/agiledragon/gomonkey/[email protected]

Test Method

$ go test . ./test -gcflags=all=-l

Using gomonkey

Please refer to the test cases as idioms, very complete and detailed.

GitHub Issues· 0 open

View all on GitHub

No open issues yet, or sync has not completed.

Highlights

  • •support a patch for a function
  • •support a patch for a public member method
  • •support a patch for a private member method
  • •support a patch for a interface
  • •support a patch for a function variable
  • •support a patch for a global variable
  • •support patches of a specified sequence for a function
  • •support patches of a specified sequence for a member method
  • •support patches of a specified sequence for a interface
  • •support patches of a specified sequence for a function variable

> Tags

Gofunctionfunction-variableglobal-variablegomonkey

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言