Releases: cweill/gotests
v1.9.0 - AI-Powered Test Generation
🤖 AI-Powered Test Generation
This release adds AI-powered test case generation using local LLMs via Ollama, enabling automatic generation of intelligent, realistic test cases.
✨ Key Features
- 🧠 Intelligent Test Cases: AI analyzes function implementation to generate realistic test values, edge cases, and error conditions
- 🏠 Local-First & Private: Uses Ollama to run LLMs locally - your code never leaves your machine
- ⚡ Fast Small Models: Default qwen2.5-coder:0.5b model (400MB) generates tests in seconds
- 🎯 Smart Coverage: Automatically identifies edge cases, error conditions, and validation logic
- 🔧 Flexible: Support for simple types, complex types, methods, variadic params, and multiple return values
- 📊 Configurable: Adjust min/max test cases, choose different models, or use custom endpoints
🚀 Quick Start
# Install Ollama (one-time setup)
curl -fsSL https://ollama.com/install.sh | sh
ollama serve &
ollama pull qwen2.5-coder:0.5b
# Generate tests with AI
gotests -all -ai -w yourfile.go📝 Example
Given this function:
func CalculateDiscount(price float64, percentage int) (float64, error) {
if price < 0 {
return 0, errors.New("price cannot be negative")
}
if percentage < 0 || percentage > 100 {
return 0, errors.New("percentage must be between 0 and 100")
}
return price - (price * float64(percentage) / 100.0), nil
}AI generates:
- ✅ Valid input test case
- ✅ Negative price error case
- ✅ Invalid percentage error case
- ✅ Proper error handling and assertions
🎛️ Configuration Options
# Use different model
gotests -all -ai -ai-model llama3.2:latest -w file.go
# Generate specific number of test cases (min = max)
gotests -all -ai -ai-min-cases 5 -ai-max-cases 5 -w file.go
# Generate range of test cases (AI chooses 3-7)
gotests -all -ai -ai-min-cases 3 -ai-max-cases 7 -w file.go
# Custom Ollama endpoint
gotests -all -ai -ai-endpoint http://custom:11434 -w file.go🔒 Privacy & Security
- ✅ Local-first by default - Using Ollama keeps all data on your machine
- ✅ Offline operation - Works completely offline with local models
⚠️ Function bodies are analyzed - Business logic and code comments are sent to the LLM- 🔒 Recommendation: Avoid using
-aion code containing secrets or API keys
📊 Test Coverage Improvements
- Increased overall project coverage from 28.1% to 84.6% (#196)
- Added comprehensive tests for:
- internal/goparser package
- internal/models package
- internal/output package
- internal/render package
- gotests/process package
📚 Documentation Enhancements
- Added godoc comments to all exported functions (#195)
- Expanded README with:
- AI-powered test generation section
- Quick start examples
- Privacy and security considerations
- Configuration options and examples
🛠️ Technical Implementation
New Packages:
internal/ai- AI provider abstraction layer- Ollama provider with health checks and retries
- Go-specific prompt engineering
- Response parsing and validation
- E2E test suite with golden file validation
CLI Flags:
-ai- Enable AI test case generation-ai-model- Select model (default: qwen2.5-coder:0.5b)-ai-endpoint- Ollama endpoint (default: http://localhost:11434)-ai-min-cases- Minimum test cases to generate (default: 3)-ai-max-cases- Maximum test cases to generate (default: 10)
Architecture:
- Provider-based design for future LLM support
- Language-agnostic core with Go-specific implementation
- Graceful fallback to TODO comments on generation failure
- Integration with existing template rendering pipeline
🐛 Known Issues
- Issue #197: 4 out of 11 E2E tests disabled due to environment-dependent LLM non-determinism
- Does not affect functionality, only E2E test validation
- 7 E2E tests pass consistently on first attempt
- Will be addressed in future patch release
📦 Installation
go install github.com/cweill/gotests/[email protected]🙏 Credits
🤖 Developed with assistance from Claude Code
Full Changelog: v1.8.0...v1.9.0
v1.8.0 - Full Go Generics Support
🎉 Full Go Generics Support
This release adds complete support for Go generics (type parameters), enabling gotests to generate tests for generic functions and methods on generic types.
✨ Key Features
-
🔧 Generic Functions: Generate tests for functions with type parameters
func FindFirst[T comparable](slice []T, target T) (int, error)
-
🏗️ Generic Types: Support for methods on generic types
type Set[T comparable] struct { ... } func (s *Set[T]) Add(v T)
-
🎯 All Constraint Types:
any,comparable, union types (int64 | float64), approximation (~int) -
🧠 Smart Type Mapping: Intelligent defaults for type instantiation
any→intcomparable→string- Union types → first option
- Approximation → underlying type
-
🔄 Multiple Type Parameters: Handles functions like
Pair[T, U any]
📊 Test Coverage
- ✅ 97.5% main package coverage
- ✅ 83.5% overall project coverage
- ✅ 100% coverage on all new parser functions
- ✅ 8 comprehensive generic test patterns
🔧 Technical Improvements
Parser Enhancements:
- New
parseTypeDecls()extracts type parameters from type declarations - New
parseTypeParams()parses AST field lists - New
extractBaseTypeName()handles receiver types
Template Functions:
TypeArgs- generates concrete type arguments for callsFieldType- substitutes type parameters in field declarationsReceiverType- substitutes type parameters in receiver instantiations
Model Updates:
- New
TypeParamstruct - Added
TypeParamsfield toFunction - Helper methods:
IsGeneric(),HasGenericReceiver()
📚 Documentation
Added comprehensive "Go Generics Support" section to README with:
- Example: Generic function test generation
- Example: Methods on generic types
- Type constraint mapping reference
🐛 Fixes
Closes #165
📦 Installation
go install github.com/cweill/gotests/[email protected]🙏 Credits
🤖 Developed with assistance from Claude Code
Full Changelog: v1.7.0...v1.8.0
v1.7.4
What's New in v1.7.4
This release fixes two important bugs that improve test correctness and restore broken functionality.
Bug Fixes
🐛 Fixed wantErr Test Logic (PR #169)
When a test expects an error (tt.wantErr == true), gotests now correctly skips result validation instead of checking potentially undefined return values.
Before:
if (err != nil) != tt.wantErr {
t.Errorf("Foo() error = %v, wantErr %v", err, tt.wantErr)
continue
}
// Bug: Still checks results even when error is expected!
if got != tt.want {
t.Errorf("Foo() = %v, want %v", got, tt.want)
}After:
if (err != nil) != tt.wantErr {
t.Errorf("Foo() error = %v, wantErr %v", err, tt.wantErr)
continue
}
if tt.wantErr {
return // ← Fixed: Skip result checks when error expected
}
if got != tt.want {
t.Errorf("Foo() = %v, want %v", got, tt.want)
}This prevents false test failures and ensures tests behave correctly when expecting errors.
Thanks to @arifmahmudrana for identifying this issue!
🐛 Fixed -template_params Flag (Issue #149)
The -template_params flag was defined but never actually used due to a bug from PR #90. This flag now works correctly!
Usage:
# Pass template parameters as JSON string
$ gotests -template_params '{"key":"value"}' -all file.go
# Or use a file (takes precedence)
$ gotests -template_params_file params.json -all file.goThis is useful when calling gotests from other tools with custom templates.
Thanks to @butuzov for identifying this bug and @cweill for the fix suggestion!
Installation
go install github.com/cweill/gotests/[email protected]Full Changelog: v1.7.3...v1.7.4
v1.7.3
What's New in v1.7.3
This is a security update that addresses multiple CVEs by updating dependencies.
Security Fixes
🔒 Updated golang.org/x/tools to fix CVEs
Updated golang.org/x/tools from v0.0.0-20191109212701 (November 2019) to v0.38.0 (latest) to address multiple security vulnerabilities:
- CVE-2021-38561 - Fixed
- CVE-2019-9512 - Fixed
- CVE-2020-29652 - Fixed
Changes
- Updated
golang.org/x/toolsfrom 2019 version to v0.38.0 - Updated Go directive to 1.24.0 (with toolchain go1.24.5)
- Added indirect dependencies:
golang.org/x/modv0.29.0,golang.org/x/syncv0.17.0 - Fixed test code compatibility with stricter format string checking in newer x/tools
All tests pass with the updated dependencies.
Installation
go install github.com/cweill/gotests/[email protected]Important Note
We recommend all users update to this version to ensure you have the latest security fixes.
Full Changelog: v1.7.2...v1.7.3
Thanks to @testwill for identifying these security vulnerabilities!
v1.7.2
What's New in v1.7.2
This is a small cleanup release with code quality improvements and documentation updates.
Improvements
🧹 Code Cleanup
- Remove unnecessary type conversion (#170) - Simplified code in
generateTest()by removing redundant type conversion. Thanks to @fengxuway!
📚 Documentation
- Update VS Code link (#167) - Changed Visual Studio Code link to point directly to gotests-specific configuration documentation for easier setup. Thanks to @davidhsingyuchen!
Installation
go install github.com/cweill/gotests/[email protected]Full Changelog: v1.7.1...v1.7.2
v1.7.1
What's New in v1.7.1
This release adds two highly-requested features to improve the gotests experience.
New Features
🧪 go-cmp Support (-use_go_cmp)
Generate tests using google/go-cmp instead of reflect.DeepEqual for better test assertions and diff output.
$ gotests -use_go_cmp -all -w example.goGenerated tests will use cmp.Equal() for comparisons and cmp.Diff() in error messages, providing much clearer output when tests fail.
Example output:
if !cmp.Equal(tt.want, got) {
t.Errorf("Foo() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(tt.want, got))
}Resolves #155 (thanks to @butuzov for the original PR!)
📋 Version Information (-version)
Check which version of gotests you're running:
$ gotests -version
gotests v1.7.1
Go version: go1.22.0
Git commit: 5252e0b...
Build time: 2025-10-21T02:15:00ZThis helps with troubleshooting and verifying you have the latest release.
Resolves #133
Housekeeping
Installation
go install github.com/cweill/gotests/[email protected]Full Changelog: v1.7.0...v1.7.1
v1.7.0 - Major Modernization Release
v1.7.0 - Major Modernization Release
After 5 years since v1.6.0, we're excited to release v1.7.0 with major improvements and modernizations! 🎉
✨ New Features
Recursive Directory Support
You can now generate tests for entire directory trees using the ... pattern:
gotests -all pkg/...This will recursively generate tests for all Go files in the pkg directory and its subdirectories. Fixes #186.
Cleaner Generated Code
Generated tests now use Go 1.22+ loop variable scoping, eliminating the need for the tt := tt shadowing pattern. Tests are now cleaner and more readable.
Better Error Handling
Subtests with return values now use t.Fatalf() instead of t.Errorf() + return, providing clearer test failure semantics and preventing misleading output. Thanks to PR #184.
🔧 Improvements
BREAKING: Minimum Go Version
- Minimum Go version increased from 1.6 to 1.22
- Leverages modern Go features for cleaner generated code
- Aligns with Go's official support policy
Dependency Reduction
- Replaced third-party bindata tools with stdlib
embedpackage (PR #181) - Removed 834+ lines of generated code
- Simplified build process - no more
go generateneeded - Better maintainability and reduced external dependencies
Bug Fixes
- Fixed import path bug when receiver types and methods are in different files (PR #179)
- Now correctly collects imports from all files in the package
- Prevents compilation errors in generated test files
Template Improvements
- Proper
t.Parallel()placement at top-level test functions (fixes #188) - Satisfies
tparallellinter requirements - Better parallel test execution
Documentation & Installation
- Updated README to use
go installinstead of deprecatedgo get(PR #180) - Documented the
-namedflag for map-based table tests (PR #185) - Added CHANGELOG.md for tracking changes
- Added CLAUDE.md for AI-assisted development
📦 CI/CD Updates
- Updated GitHub Actions to test Go 1.22.x, 1.23.x, 1.24.x, and 1.25.x
- Modernized actions: setup-go v2→v5, checkout v2→v4
- Simplified coverage reporting with coverallsapp/github-action@v2
- Fixed bot commit support for automated workflows
📊 Statistics
- 834+ lines of generated bindata code removed
- 5 PRs integrated
- 2 issues fixed
- 4 Go versions tested in CI (was 8, now focused on recent versions)
🙏 Thanks
Special thanks to the contributors whose PRs were integrated in this release:
- PR #184 (t.Fatalf improvement)
- PR #185 (documentation)
- PR #180 (go install)
- PR #181 (embed package)
- PR #179 (import fix)
And to everyone who reported issues and helped maintain this project!
📝 Installation
go install github.com/cweill/gotests/gotests@latest🔗 Full Changelog
See CHANGELOG.md for complete details.
Version 1.6.0
Merge pull request #146 from cweill/develop Merge `develop` into `master`
Version 1.5.3
v1.5.3 Fix TravisCI and add go1.11 and go1.12 support (#94) (#95)
Version 1.5.2
Revert "Update tests to use subtests." This reverts commit efeb9cff0e4b88d0cf351234f917dd38c6c3894c.