An all-in-one Go testing library providing monkey patching, stack tracing, and function trapping via IR rewriting.
xgo is an all-in-one testing library for Go that provides advanced mocking, debugging, and code coverage tools. It solves the problem of intrusive testing by enabling runtime function patching without requiring interface abstraction, and offers visual stack tracing and incremental coverage analysis.
Go developers writing unit tests who need flexible mocking, debugging complex call stacks, or improving test coverage without refactoring code to use interfaces.
Developers choose xgo because it offers goroutine-safe monkey patching, visual debugging tools, and seamless integration with existing Go tests—all without the compatibility issues of assembly-based alternatives like bouk/monkey.
All-in-one go testing library
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Enables mocking of functions, methods, and variables without requiring interface abstraction, using Patch and Mock APIs for runtime interception as demonstrated in the quick start.
Mocks are per-goroutine and automatically cleaned up, allowing safe concurrent test execution without cross-contamination, as highlighted in the concurrent safety section.
Provides hierarchical stack trace visualization with the --strace flag or trace.Trace(), making it easier to debug complex call flows with output files like TestTrace.json.
Extends go tool cover to highlight coverage gaps specifically in modified code lines, aiding in focused testing efforts as shown in the incremental coverage tool.
The IR rewriting preprocessing step adds significant overhead to compilation and test execution, which can slow down development cycles, especially for large projects.
Requires setting up an instrumented GOROOT with xgo setup and modifying IDE settings, adding initial setup steps and potential integration hurdles.
Relies on Go's IR representation, which may break with future compiler changes, posing a maintenance risk compared to more stable interface-based mocking.