TestGen AI π€π§ͺ
An AI-powered CLI tool that automatically generates Dart unit tests using Google's Gemini AI. Improve your test coverage with intelligent test case generation!
Features β¨
- π Generate tests for Dart functions/classes
- π§ AI-powered edge case detection
- βοΈ Simple CLI interface
- π Integrates with
package:coverage(future update)
Quick Start
1. Install
dart pub add test_gen
2. Configuration
i. Get Gemini API Key
ii. Set environment variable:
Linux/macOS
export GEMINI_API_KEY="your_key"
Windows
$env:GEMINI_API_KEY="your_key"
3. Generate tests
dart run test_gen -i lib/subfolder(if any)/file_name.dart
E.g:
dart run test_gen -i lib/math.dart
Example π§ͺ
Input File (lib/math.dart)
int add(int a, int b) => a + b;
Generated Test (test/math_test.dart):
import 'package:test/test.dart';
import '../lib/math.dart';
void main() {
test('adds two numbers', () {
expect(add(2, 3), 5);
});
}
CLI Options
| Option | Short | Description | Default |
|---|---|---|---|
--input |
-i |
Input Dart file (required) | - |
--output |
-o |
Output directory | test/ |
--verbose |
-v |
Show detailed output | false |
Troubleshooting π¨
Common Issues
Missing API Key: Ensure GEMINI_API_KEY is set
Invalid Input Path: Verify file exists and is a Dart file
Test Validation Errors: Review generated tests for AI hallucinations
Features Roadmap πΊοΈ
-
Coverage analysis integration
-
Batch processing for entire directories
-
Test validation system
-
Custom prompt templates
Building from Source π οΈ
Clone repository
git clone https://github.com/yourusername/test_gen_dart.git
cd test_gen_dart
Install dependencies
dart pub get
Run development version
dart run test_gen -i lib/example.dart
Project Structure
| Path | Type | Purpose |
|---|---|---|
bin/test_gen.dart |
CLI Entry | Command line interface handling and argument parsing |
lib/test_generator.dart |
Core Logic | Contains implementation of test generation logic |
lib/sample/ |
Examples | Sample input files |
test/ |
Unit Tests | Sample output tests for verification |