github cweill/gotests v1.9.0
v1.9.0 - AI-Powered Test Generation

one day ago

🤖 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 -ai on 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/gotests@v1.9.0

🙏 Credits

🤖 Developed with assistance from Claude Code


Full Changelog: v1.8.0...v1.9.0

Don't miss a new gotests release

NewReleases is sending notifications on new releases.