Skip to content

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-from now 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)
  • --pkg flag — package name for generated mock files (required in standalone mode)
  • Single-segment qualifier fallback — --mock-from "io.Writer" retries as direct import path when io isn't imported by the consuming file

Changed

  • gen command now accepts zero positional args when --mock-from is present (standalone mode)
  • --mock-from help text documents all 4 spec formats

v0.1.5 - [unreleased]

Added

  • gen-cases command — reads a .testspec.yaml and materializes test case entries into an existing _test.go
  • Inserts struct literal entries into the tests slice with correct field values from the spec
  • Generates before/after function 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; --force replaces them
  • --dry-run previews output without writing; --no-hints omits ai-hint comments; --verbose prints a generation summary
  • Resolves target _test.go automatically from package + function name (override with --output)
  • internal/spec package — YAML types and ParseFile() for .testspec.yaml format
  • internal/gencases package — AST-based analysis + text-based insertion pipeline

Added

  • AI agent skills — skills/ directory promoted to root with <name>/SKILL.md structure for OpenCode, Claude Code, Cursor, Codex, Gemini compatibility
  • scripts/install.shcurl | bash installer for AI agent skills

Changed

  • Moved research/skills/skills/ (first-class citizen at repo root)
  • skills/AGENTS.md — paths updated to reflect new skill locations
  • README.md — AI Agent Skills section updated with curl | bash install command

Removed

  • Removed stale root skills/ directory (had corrupt gen-test-cases content)

v0.1.4 - [unreleased]

Added

  • Fixed-size array parameter detection — [N]T params now correctly identified in analyzer
  • HasArrayResult flag on FuncSummary and ScanResult for array return type detection
  • SuggestStyle now recommends check style for functions returning arrays (like slices)

Fixed

  • typeToString now preserves array length (e.g. [100]T instead of []T) for both parameters and results
  • extractTypePrefix handles [N] prefix, enabling correct identification of array params/results
  • qualifiedTypeName correctly drills into array element types for package qualification
  • placeholderValue generates [N]T{} zero-value literals for arrays instead of invalid nil
  • inspectSignature detects [N] arrays when checking HasSliceResult fallback
  • Added unit tests for qualifiedTypeName and placeholderValue with array types

v0.1.3 - 2026-05-08

Added

  • Channel type detection and support in analyzer — IsChannel and ChanDir fields on ParamInfo and ResultInfo
  • HasChannelParam / HasChannelResult flags on FuncSummary and ScanResult
  • Full channel direction support: chan, chan<-, <-chan in typeToString, extractTypePrefix, and resolveTypeExpr
  • qualifiedTypeName now handles channel prefixes for correct type qualification
  • placeholderValue returns nil for channel types

Changed

  • Go toolchain go.mod updated from go 1.26.1 to go 1.26.2

Fixed

  • Fixed issue with ignored _ (blank identifier) params
  • Fixed missing imports when merging tests
  • Fixed error when no .go file is found at project root but go.mod and go.sum are present
  • Report command now shows source file location for each function

v0.1.2 - 2026-05-07

Added

  • --mock-from accepts bare interface names (e.g. --mock-from mockI2C) and .InterfaceName (e.g. .I2CTransport) for interfaces in the same package
  • SourceFile field to scan results (via internal/analyzer)

Changed

  • Renamed --test-style flag to --style
  • Moved package loading logic to getPackages() helper in internal/analyzer/helpers.go
  • ScanPackage now handles module root (.) with no .go files by retrying with ./...
  • ScanPackage now merges results from multiple packages (e.g. ./...)
  • MergeTestFile now accepts and injects imports into merged test files
  • writeOutput / writeToFile now 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 .go file is found at project root but go.mod and go.sum are 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
  • SourceFile field 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
  • gen command: generate test scaffolding for a function or method
  • FuncSpec accepts plain function name (New, CreateUser) or receiver-qualified method (Service.CreateUser)
  • Auto-detects output file (<source>_test.go) when --output is omitted
  • --dry-run flag: prints generated code to stdout without writing
  • --verbose flag: dumps parsed FuncInfo JSON to stderr before generating
  • --mock-from qualifier.InterfaceName: generates a testify mock for the named interface (repeatable flag)
  • -o - writes to stdout explicitly
  • inspect command: dumps FuncInfo JSON for a function — useful for diagnosing wrong signatures or missing types before running gen
  • report command: scans all exported functions and methods in a package and shows test coverage status
  • --format text|table|json output modes
  • Shows interface dependencies and whether mock files exist
  • Prints exact go-testgen gen command to run for each untested function

Test Generation Styles

  • check style (default): table-driven tests with closure-based check functions
  • Generates a checkXxxFn type alias and checkXxx variadic 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
  • table style: table-driven tests with want value comparison fields
  • simple style: standalone test functions without a table

Mock Generation

  • --mock-from qualifier.InterfaceName generates a complete testify mock
  • Written to mock_<interfacename>_test.go next 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.go exists 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; goimports applied when available in PATH
  • suggest module: infers go-testgen gen commands for untested functions
  • factory module: selects generator implementation based on style

Configuration (internal/config)

  • Viper-based config from .go-testgen.yaml
  • Search order: explicit --style flag → 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, version subcommands
  • version command 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

go install github.com/padiazg/go-testgen@latest

Or build from source:

make build
make install