You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@emou - I like your idea. Generating test cases fits nicely with the goal of gotests: to make writing tests easier. If you could outline a design of how this would work, I would be happy to critique it and provide guidance.
One of the core challenges is figuring out how to seamlessly get testing/quick to generate test cases and then pass them to gotests. It's not immediately clear how we can get gotests to execute test code, since it's a binary separate from your code which just performs static analysis right now.
I'd like to propose an approach to address this issue using local LLM models to generate actual test cases, complementing gotests' existing scaffolding.
The Problem
Currently, gotests generates excellent table-driven test scaffolding but leaves test case creation to developers:
tests:= []struct {
namestringargsargswantint
}{
// TODO: Add test cases. ← Developer must fill this manually
}
Proposed Solution
Add an optional -ai flag that generates test cases using local LLM models:
✅ Stays within gotests' static analysis model - No runtime execution required
✅ Completely free - Uses local open-source models via Ollama
✅ Privacy-first - Code never leaves your machine
✅ Opt-in - Doesn't change existing behavior without the flag
✅ Fast - Tiny models generate cases in 2-3 seconds
✅ Works offline - No internet required after model download
MVP Design
Core Features
Single Provider: Ollama (local LLM runtime) Default Model: qwen2.5-coder:0.5b (500MB, runs on any laptop) Test Cases: 3 per function (normal, edge, error cases) Validation: In-memory compilation check with retry logic
End-User Workflow
First-time setup (one-time):
# Install Ollama
$ curl -fsSL https://ollama.com/install.sh | sh
# Pull tiny code model (~400MB)
$ ollama pull qwen2.5-coder:0.5b
Ongoing usage:
# Same as before, just add -ai flag
$ gotests -ai -w myfile.go
@s-kostyaev Great question. The AI feature supports customizable test case counts. We provide two
flags:
-ai-min-cases (default: 3) - minimum number of test cases to generate
-ai-max-cases (default: 10) - maximum number of test cases to generate
The LLM determines how many test cases to generate within this range based on the function's
complexity. For complex functions with multiple branches, you can increase these limits:
This allows the AI to generate anywhere from 5-20 test cases depending on what it determines is
appropriate for the function. The validation limits are:
Minimum: at least 1 case
Maximum: up to 100 cases
So yes, it's fully customizable! The default 3-10 range was chosen as a reasonable starting point
that balances coverage with generation time, but you can adjust it based on your needs.
Activity
cweill commentedon Apr 8, 2017
@emou - I like your idea. Generating test cases fits nicely with the goal of gotests: to make writing tests easier. If you could outline a design of how this would work, I would be happy to critique it and provide guidance.
One of the core challenges is figuring out how to seamlessly get
testing/quickto generate test cases and then pass them to gotests. It's not immediately clear how we can get gotests to execute test code, since it's a binary separate from your code which just performs static analysis right now.cweill commentedon Oct 21, 2025
Proposal: LLM-Based Test Case Generation
I'd like to propose an approach to address this issue using local LLM models to generate actual test cases, complementing gotests' existing scaffolding.
The Problem
Currently, gotests generates excellent table-driven test scaffolding but leaves test case creation to developers:
Proposed Solution
Add an optional
-aiflag that generates test cases using local LLM models:Generated output:
Why This Approach?
Unlike property-based testing (original issue proposal), this:
MVP Design
Core Features
Single Provider: Ollama (local LLM runtime)
Default Model: qwen2.5-coder:0.5b (500MB, runs on any laptop)
Test Cases: 3 per function (normal, edge, error cases)
Validation: In-memory compilation check with retry logic
End-User Workflow
First-time setup (one-time):
Ongoing usage:
# Same as before, just add -ai flag $ gotests -ai -w myfile.goExample: Error Handling
Source code:
Generated test:
Architecture
Provider Interface (Extensible)
Compilation Validation
Uses Go's built-in
go/parserandgo/typespackages for in-memory validation:Retry logic with feedback:
File Structure
Template Changes
Minimal modification to
internal/render/templates/function.tmpl:Recommended Models
All run locally via Ollama:
Users can switch models with
-ai-model=qwen2.5-coder:7bWhat It Handles (90% Use Cases)
✅ Simple functions (math, string manipulation)
✅ Functions returning errors
✅ Basic types (int, string, bool, []byte)
✅ Edge cases (zero, nil, negative values)
✅ Boundary conditions
✅ Error scenarios
Future enhancements (remaining 10%):
Implementation Phases
Phase 1: MVP (This Proposal)
-aiflagDeliverable: Working
-aiflag with qwen2.5-coder:0.5bPhase 2: Multi-Provider
Phase 3: Quality & Polish
Phase 4: Advanced Features
Why Ollama + Tiny Models?
Ollama is the Docker of LLMs:
Tiny models (0.5B-7B parameters):
feat: add AI test generation foundation (WIP)
s-kostyaev commentedon Oct 23, 2025
Why only 3 cases? It's not enough for complex functions with multiple branches. I think it should be customizable. Or 3 cases only for MVP?
feat: AI-powered test case generation (#194)
cweill commentedon Oct 23, 2025
@s-kostyaev Great question. The AI feature supports customizable test case counts. We provide two
flags:
-ai-min-cases (default: 3)- minimum number of test cases to generate-ai-max-cases (default: 10)- maximum number of test cases to generateThe LLM determines how many test cases to generate within this range based on the function's
complexity. For complex functions with multiple branches, you can increase these limits:
gotests -ai -ai-min-cases=5 -ai-max-cases=20 -all path/to/your/file.goThis allows the AI to generate anywhere from 5-20 test cases depending on what it determines is
appropriate for the function. The validation limits are:
So yes, it's fully customizable! The default 3-10 range was chosen as a reasonable starting point
that balances coverage with generation time, but you can adjust it based on your needs.