test_gen 0.1.1

SDKdartflutter
Platformandroidioswindowslinuxmacos

A CLI tool that generates Dart tests using Gemini AI

TestGen AI 🤖🧪

Pub Version License: MIT

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

OptionShortDescriptionDefault
--input-iInput Dart file (required)-
--output-oOutput directorytest/
--verbose-vShow detailed outputfalse

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

PathTypePurpose
bin/test_gen.dartCLI EntryCommand line interface handling and argument parsing
lib/test_generator.dartCore LogicContains implementation of test generation logic
lib/sample/ExamplesSample input files
test/Unit TestsSample output tests for verification

Disclaimer: Generated tests should be reviewed and may require manual adjustment. Critical systems should not rely solely on AI-generated tests.