Changelog¶
All notable changes to go-testgen will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
v0.2.1 - 2026-06-16¶
Added¶
--mock-fromnow accepts full import paths (e.g.io.Writer,net/http.Handler,github.com/x/y.Iface) — the interface is loaded directly without resolving through consuming package imports- Standalone mock mode —
go-testgen gen --mock-from <spec> --pkg <name> --output <file>generates mocks without a consuming package (stdlib and external interfaces) --pkgflag — package name for generated mock files (required in standalone mode)- Single-segment qualifier fallback —
--mock-from "io.Writer"retries as direct import path whenioisn't imported by the consuming file
Changed¶
gencommand now accepts zero positional args when--mock-fromis present (standalone mode)--mock-fromhelp text documents all 4 spec formats
v0.1.5 - [unreleased]¶
Added¶
gen-casescommand — reads a.testspec.yamland materializes test case entries into an existing_test.go- Inserts struct literal entries into the
testsslice with correct field values from the spec - Generates
before/afterfunction stubs with signature inferred from the existing AST - Emits
// ai-hint:comments so a generative AI can complete concrete values - Idempotent: skips entries that already exist by name;
--forcereplaces them --dry-runpreviews output without writing;--no-hintsomits ai-hint comments;--verboseprints a generation summary- Resolves target
_test.goautomatically from package + function name (override with--output) internal/specpackage — YAML types andParseFile()for.testspec.yamlformatinternal/gencasespackage — AST-based analysis + text-based insertion pipeline
Added¶
- AI agent skills —
skills/directory promoted to root with<name>/SKILL.mdstructure for OpenCode, Claude Code, Cursor, Codex, Gemini compatibility scripts/install.sh—curl | bashinstaller for AI agent skills
Changed¶
- Moved
research/skills/→skills/(first-class citizen at repo root) skills/AGENTS.md— paths updated to reflect new skill locationsREADME.md— AI Agent Skills section updated withcurl | bashinstall command
Removed¶
- Removed stale root
skills/directory (had corruptgen-test-casescontent)
v0.1.4 - [unreleased]¶
Added¶
- Fixed-size array parameter detection —
[N]Tparams now correctly identified in analyzer HasArrayResultflag onFuncSummaryandScanResultfor array return type detectionSuggestStylenow recommendscheckstyle for functions returning arrays (like slices)
Fixed¶
typeToStringnow preserves array length (e.g.[100]Tinstead of[]T) for both parameters and resultsextractTypePrefixhandles[N]prefix, enabling correct identification of array params/resultsqualifiedTypeNamecorrectly drills into array element types for package qualificationplaceholderValuegenerates[N]T{}zero-value literals for arrays instead of invalidnilinspectSignaturedetects[N]arrays when checkingHasSliceResultfallback- Added unit tests for
qualifiedTypeNameandplaceholderValuewith array types
v0.1.3 - 2026-05-08¶
Added¶
- Channel type detection and support in analyzer —
IsChannelandChanDirfields onParamInfoandResultInfo HasChannelParam/HasChannelResultflags onFuncSummaryandScanResult- Full channel direction support:
chan,chan<-,<-chanintypeToString,extractTypePrefix, andresolveTypeExpr qualifiedTypeNamenow handles channel prefixes for correct type qualificationplaceholderValuereturnsnilfor channel types
Changed¶
- Go toolchain
go.modupdated fromgo 1.26.1togo 1.26.2
Fixed¶
- Fixed issue with ignored
_(blank identifier) params - Fixed missing imports when merging tests
- Fixed error when no
.gofile is found at project root butgo.modandgo.sumare present - Report command now shows source file location for each function
v0.1.2 - 2026-05-07¶
Added¶
--mock-fromaccepts bare interface names (e.g.--mock-from mockI2C) and.InterfaceName(e.g..I2CTransport) for interfaces in the same packageSourceFilefield to scan results (via internal/analyzer)
Changed¶
- Renamed
--test-styleflag to--style - Moved package loading logic to
getPackages()helper ininternal/analyzer/helpers.go ScanPackagenow handles module root (.) with no.gofiles by retrying with./...ScanPackagenow merges results from multiple packages (e.g../...)MergeTestFilenow accepts and injects imports into merged test fileswriteOutput/writeToFilenow pass import map for smart import injection
Fixed¶
- Fixed issue with ignored
_(blank identifier) params - Fixed missing imports when merging tests
- Fixed error when no
.gofile is found at project root butgo.modandgo.sumare present - Report command now shows source file location for each function
v0.1.1 - 2026-04-23¶
Fixed¶
- Factory function instantiation now uses proper placeholder values instead of hardcoded
nil - Report command now shows source file location for each function
Changed¶
- Fixed repo name in GitLab CI settings
- Renamed site from "go-testgen" to "Go TestGen" in docs
Added¶
- Gitea CI configuration files
- Homebrew install method documentation in docs
SourceFilefield to scan results for better reporting
v0.1.0 - 2026-04-16¶
Added¶
Core Pipeline: analyze → generate → write¶
- Three-stage pipeline: AST analysis via
go/packages→ template-based scaffolding → file write with smart merge gencommand: generate test scaffolding for a function or methodFuncSpecaccepts plain function name (New,CreateUser) or receiver-qualified method (Service.CreateUser)- Auto-detects output file (
<source>_test.go) when--outputis omitted --dry-runflag: prints generated code to stdout without writing--verboseflag: dumps parsedFuncInfoJSON to stderr before generating--mock-from qualifier.InterfaceName: generates a testify mock for the named interface (repeatable flag)-o -writes to stdout explicitlyinspectcommand: dumpsFuncInfoJSON for a function — useful for diagnosing wrong signatures or missing types before runninggenreportcommand: scans all exported functions and methods in a package and shows test coverage status--format text|table|jsonoutput modes- Shows interface dependencies and whether mock files exist
- Prints exact
go-testgen gencommand to run for each untested function
Test Generation Styles¶
checkstyle (default): table-driven tests with closure-based check functions- Generates a
checkXxxFntype alias andcheckXxxvariadic collector - Each assertion is an independent named closure composable per test case
before func(*ReceiverType)field in the table for mock setup and state mutation- Context parameters (
context.Context) are injected automatically, not exposed in the table tablestyle: table-driven tests withwantvalue comparison fieldssimplestyle: standalone test functions without a table
Mock Generation¶
--mock-from qualifier.InterfaceNamegenerates a complete testify mock- Written to
mock_<interfacename>_test.gonext to the test file - All interface methods implemented; pointer/slice returns use comma-ok type assertion (
r, _ := args.Get(0).(*T)) — safe for nil returns - Existing mock files are never overwritten
Smart Merge¶
- If target
_test.goexists but does not contain the test function: appends the new test and injects missing imports - Never overwrites an existing test function
Static Analyzer (internal/analyzer)¶
- Loads packages via
golang.org/x/tools/go/packages - Extracts
FuncInfo: name, package, import path, receiver, params, results,HasError,HasContext - Resolves interface params — enables mock injection suggestions
- Extracts struct fields from receiver — used for constructor (
New) check generation - Resolves required imports for the generated test file
Generator (internal/generator)¶
- Template-based code generation using
text/template - Output formatted with
go/format.Source;goimportsapplied when available inPATH suggestmodule: infersgo-testgen gencommands for untested functionsfactorymodule: selects generator implementation based on style
Configuration (internal/config)¶
- Viper-based config from
.go-testgen.yaml - Search order: explicit
--styleflag → cwd →$HOME→ hardcoded defaults - Configurable: variable names, testify usage, TODO placeholders, check type suffix, mock/check generation
CLI (cmd/)¶
- Cobra-based CLI with
gen,inspect,report,versionsubcommands versioncommand reports build version
Build & Release¶
- GoReleaser configuration for multi-platform releases
- GitHub Actions CI/CD workflow
- Platform targets: Linux x86_64/arm64, macOS x86_64/arm64
- Static binaries (
CGO_ENABLED=0)
How to Install¶
Or build from source: