Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
All-in-one go testing library
| Date | Stars |
|---|---|
| 2026-07-24 | 431 |
| 2026-07-25 | 430 |
| 2026-07-28 | 430 |
| 2026-07-30 | 430 |
| 2026-08-07 | 431 |
| 2026-08-23 | 431 |
| 2026-09-10 | 430 |
| 2026-09-12 | 431 |
| 2026-09-20 | 430 |
Today
-1 stars today
This week
-1 stars this week
This month
-1 stars this month
Momentum
35.0
growth rate 0.00%/day
# xgo
[](https://pkg.go.dev/github.com/xhd2015/xgo)
[](https://goreportcard.com/report/github.com/xhd2015/xgo)
[](https://join.slack.com/t/golang-xgo/shared_invite/zt-2ixe161jb-3XYTDn37U1ZHZJSgnQi6sg)
[](https://github.com/xhd2015/xgo/actions)
[](https://github.com/xhd2015/xgo/actions)
[](https://github.com/avelino/awesome-go)
**English | [简体中文](./README_zh_cn.md)**
`xgo` provides *all-in-one* test utilities for golang, including:
- [API](#api):
- [Mock](#patch)
- [Trace](#trace)
- [Trap](#trap)
- [Tools](#tools):
- [Test Explorer](#test-explorer)
- [Incremental Coverage](#incremental-coverage)
- [IDE Setup](#ide-setup)
As for the monkey patching part, `xgo` works as a preprocessor for `go run`,`go build`, and `go test`(see our [blog](https://blog.xhd2015.xyz/posts/xgo-monkey-patching-in-go-using-toolexec)).
See [Quick Start](#quick-start) and [Documentation](./doc) for more details.
[](https://youtu.be/L8oPhgqtdGg)

> *By the way, I promise you this is an interesting project.*
# Installation
```sh
go install github.com/xhd2015/xgo/cmd/xgo@latest
```
Verify the installation:
```sh
xgo version
# output:
# 1.0.x
xgo help
# output: help messages
```
If `xgo` is not found, you may need to check if `$GOPATH/bin` is added to your `PATH` variable.
For CI jobs like github workflow, see [doc/INSTALLATION.md](./doc/INSTALLATION.md).
# Requirement
`xgo` requires at least `go1.17` to compile.
There is no specific limitation on OS and Architecture.
**All OS and Architectures** are supported by `xgo` as long as they are supported by `go`.
| | x86 | x86_64 (amd64) | arm64 | any other Arch... |
|:---------|:-----------:|:-----------:|:-----------:|:-----------:|
| Linux | Y | Y | Y | Y |
| Windows | Y | Y | Y | Y |
| macOS | Y | Y | Y | Y |
| any other OS... | Y | Y | Y | Y|
# Quick Start
Let's write a unit test with `xgo`:
1. Ensure you have installed `xgo` by following the [Installation](#installation) section, and verify the installation with:
```sh
xgo version
# output
# 1.0.x
```
2. Init a go project:
```sh
mkdir demo
cd demo
go mod init demo
```
3. Add `demo_test.go`:
```go
package demo_test
import (
"testing"
"github.com/xhd2015/xgo/runtime/mock"
)
func MyFunc() string {
return "my func"
}
func TestFuncMock(t *testing.T) {
mock.Patch(MyFunc, func() string {
return "mock func"
})
text := MyFunc()
if text != "mock func" {
t.Fatalf("expect MyFunc() to be 'mock func', actual: %s", text)
}
}
```
4. Get the `github.com/xhd2015/xgo/runtime` dependency:
```sh
go get github.com/xhd2015/xgo/runtime
```
5. Test the code:
```sh
xgo test -v ./
# NOTE: xgo will take some time to setup for the first time
```
Output:
```sh
=== RUN TestFuncMock
--- PASS: TestFuncMock (0.00s)
PASS
ok demo
```
NOTE: `xgo` is used to test your code, not just `go`.
Under the hood, `xgo` preprocess your code to add mock hooks, and then calls `go` to do remaining jobs.
The above code can be found at [doc/demo](./doc/demo).
# API
## Patch
Patch given function within current goroutine.
The API:
- `Patch(fn,replacer) func()`
Cheatsheet:
```go
// package level func
mock.Patch(SomeFunc, mockFunc)
// per-instance method
// only the bound instance `v` will be mocked
// `v` can be either a struct or an interface
mock.Patch(v.Method, mockMethod)
// per-TParamExcerpt of 18,553 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:0bf702342e8796a3, topic:tracing
matched fp:0bf702342e8796a3, topic:testing