Smart test selection for Go. GTR uses call-graph analysis (CHA/VTA/RTA/static) and coverage profiling to identify which tests are affected by your code changes, then runs only those tests. Works with any Go project using the standard testing package.
| Feature | Description |
|---|---|
| Call-graph analysis | VTA, CHA, RTA, static — picks the right tests by tracing the call graph |
| Coverage strategy | Uses go test -coverprofile data to map code ↔ tests |
| Watch mode | Auto-runs affected tests on file save with desktop notifications |
| MCP server | JSON-RPC 2.0 over stdio — integrates with AI coding assistants |
| One-shot mode | gtr run for CI; gtr analyze for JSON output |
| SSA caching | Caches the SSA call graph, invalidated by file content hash |
| Structured logging | log/slog throughout for machine-parseable output |
| Auto-commit | Optionally commit on green tests |
Requires Go 1.24+ and git.
go install github.com/mmirolim/gtr@latest# Watch mode (default) — auto-test on file changes
gtr
# One-shot: find affected tests and run them
gtr run
# One-shot: print affected tests as JSON (for CI)
gtr analyze
# Start MCP server for AI assistant integration
gtr mcp| Command | Description |
|---|---|
gtr watch |
Watch for file changes, run affected tests (default) |
gtr run |
Analyze changes, run affected tests, exit |
gtr analyze |
Analyze changes, print affected tests as JSON |
gtr mcp |
Start MCP JSON-RPC 2.0 server over stdio |
gtr help |
Show help |
-C string directory to watch (default ".")
-strategy string strategy: analysis or coverage (default "analysis")
-analysis string analysis algorithm: vta, cha, rta, static (default "vta")
-run-init bool run init steps on first run (default true)
-args string args to the test binary
-auto-commit bool auto commit on tests pass (default false)
-delay int delay in Milliseconds (default 1000)
-exclude-dirs prefixes to exclude sep by comma (default "vendor,node_modules")
-exclude-file-prefix prefixes to exclude sep by comma (default "#")
-base-ref string git ref to diff against (e.g. main, HEAD~1)
Uses SSA-based call-graph analysis from golang.org/x/tools. Given a code change, GTR traces which functions are affected, walks the call graph to find test functions that transitively call those functions, and runs only those tests.
Available algorithms: vta (default, most precise), cha, rta, static.
gtr -strategy=analysis -analysis=vtaUses go test -coverprofile data. On first run, GTR runs all tests to collect coverage profiles (stored in .gtr/). On subsequent runs, it maps changed lines to covered tests.
gtr -strategy=coverageGTR exposes an MCP server for AI coding assistants.
Add to your MCP client configuration (e.g. ~/.gemini/settings.json):
{
"mcpServers": {
"gtr": {
"command": "gtr",
"args": ["mcp"]
}
}
}| Tool | Description |
|---|---|
affected_tests |
Find tests affected by code changes |
run_affected_tests |
Find and run affected tests |
file_impact_analysis |
Full impact report: changed files, functions, affected tests |
- Works with Go standard
testinglibrary only - Reflection-based calls may not be resolved (coverage strategy helps)
- Large projects may be slow on first analysis (SSA cache speeds up subsequent runs)
- May fail with "too many open files" — increase ulimit if needed
- Detect changes via
git diff(uncommitted changes or against a base ref) - Parse affected code blocks using Go AST
- Build call graph (SSA analysis) or look up coverage profiles
- Identify tests that transitively call changed functions
- Run only those tests with
go test -run <pattern>
MIT