AI-powered CLI test generator that creates comprehensive test suites for your JavaScript/TypeScript projects in seconds.
Generate high-quality, maintainable test files using advanced AI models. TestGenie analyzes your code structure, detects patterns, and creates thorough test coverage automatically.
- β¨ Features
- π Quick Start
- π Commands
- π§ͺ Test Framework
- π¨ Test Styles
- π€ AI Providers
- βοΈ Configuration
- π§ Requirements
- π― Examples
- β FAQ
- π€ Contributing
- π License
- πββοΈ Support
- Smart Code Analysis: Automatically detects functions, patterns, and dependencies
- Multi-Provider Support: OpenAI, Google Gemini, Anthropic Claude, or TestGenie API
- Comprehensive Test Generation: Creates thorough test suites with edge cases
- Advanced Async Analysis: Understands Promise flows, timing, and error handling
- React Component Intelligence: Detects JSX/TSX and generates proper React tests
- Behavioral Understanding: Analyzes component validation, form logic, and user flows
- Lightning Fast: Generate complete test suites in seconds
- Multiple Test Styles: BDD, TDD, minimal, and verbose options
- Framework Support: Jest (Mocha and Vitest coming soon!)
- Git Integration: Generate tests for changed files or specific commits
- Automatic Setup: Auto-installs dependencies and creates Jest configuration
- React/JSX Support: Full React Testing Library integration with automatic detection
- Test Coverage Analysis: Scans projects and identifies untested code
- Flexible Configuration: Customize test directories, patterns, and coverage thresholds
- Audit & Recommendations: Comprehensive coverage reports with actionable insights
- Test Execution: Built-in test runner with multiple reporters and coverage options
npm install -g testgenie-ai
# or
yarn global add testgenie-ai
# or
pnpm add -g testgenie-ai
# or
bun add -g testgenie-aitestgenie initThis interactive setup will configure:
- Test Framework: Jest (currently supported)
- Test Style: BDD, TDD, minimal, or verbose
- AI Provider: Choose from multiple providers
- Test Directory: Where to generate test files
- Coverage Settings: Minimum coverage thresholds
# Generate tests for a specific file
testgenie gen src/utils/helper.ts
# Generate tests for git changes
testgenie gen --diff
# Generate tests for changes since specific commit
testgenie gen --since HEAD~3# Run all tests with automatic setup
testgenie test
# Run tests with coverage report
testgenie test --coverage
# Watch mode for development
testgenie test --watchtestgenie --helpGet comprehensive help for all available commands and options.
# 1. Initialize project
testgenie init
# 2. Scan for files needing tests
testgenie scan
# 3. Generate tests for specific files
testgenie gen src/components/Button.tsx
# 4. Auto-generate tests for uncovered files
testgenie audit --fix
# 5. Run tests with automatic setup
testgenie test --coverage
# 6. Continuous development with watch mode
testgenie test --watchInitialize or update configuration file.
Options:
--force, -f: Overwrite existing configuration
Example:
testgenie init --forceGenerate comprehensive test files.
Arguments:
file: Specific file to generate tests for
Options:
--diff, -d: Generate tests for uncommitted git changes--since, -s <commit>: Generate tests for changes since commit--style <style>: Override test style (bdd, tdd, minimal, verbose)--output, -o <dir>: Override output directory
Examples:
# Generate tests for specific file
testgenie gen src/components/Button.tsx
# Generate tests for all changed files
testgenie gen --diff
# Generate tests since last commit
testgenie gen --since HEAD~1
# Use specific style
testgenie gen src/utils/math.js --style minimalAnalyze project for test coverage and discover files.
Arguments:
path: Directory to scan (default: current directory)
Options:
--output, -o <file>: Save results to file--format, -f <format>: Output format (json, csv, text)
Examples:
# Scan current directory
testgenie scan
# Scan specific directory with JSON output
testgenie scan src --format json --output coverage-report.json
# Quick scan of components
testgenie scan src/componentsComprehensive test coverage audit with recommendations.
Arguments:
path: Directory to audit (default: current directory)
Options:
--fix: Auto-generate tests for uncovered files--format, -f <format>: Report format (text, json, html)--deep: Enable deep analysis (file modification times, dependencies)
Examples:
# Basic audit
testgenie audit
# Auto-fix missing tests
testgenie audit --fix
# Deep analysis with JSON report
testgenie audit --deep --format jsonExecute tests in the configured test directory with automatic setup.
Arguments:
pattern: Test file pattern to run (optional)
Options:
--watch, -w: Watch mode for continuous testing--coverage, -c: Generate coverage reports--reporter, -r <format>: Test reporter format (default, json, verbose, minimal)--filter, -f <pattern>: Filter tests by name pattern--parallel, -p: Run tests in parallel (default: true)--bail, -b: Stop on first test failure--silent, -s: Suppress test output (show only results)--timeout, -t <ms>: Test timeout in milliseconds (default: 30000)
Examples:
# Run all tests with automatic setup
testgenie test
# Run tests with coverage
testgenie test --coverage
# Run specific test pattern
testgenie test --filter="Calculator"
# Watch mode with verbose output
testgenie test --watch --reporter=verbose
# Run tests in a specific directory
testgenie test src/components
# Minimal output for CI/CD
testgenie test --silent --reporter=minimalFeatures:
- Automatic Setup: Detects and installs missing Jest dependencies
- Smart Configuration: Creates optimized Jest config for your project type
- React Support: Automatically detects and configures React Testing Library
- Multiple Reporters: Choose from default, JSON, verbose, or minimal output
- Pattern Matching: Run specific tests or test suites
Display current configuration.
Example:
testgenie configTestGenie provides full Jest integration with automatic setup:
Test Generation:
- Modern ES6+ syntax and imports
- Comprehensive mocking strategies
- Async/await support
- TypeScript compatibility
- React Testing Library integration
Automatic Setup:
- Detects and installs missing Jest dependencies
- Creates optimized Jest configuration
- Configures TypeScript support when needed
- Sets up React Testing Library for JSX/TSX files
- Configures jsdom environment for React components
Test Execution:
- Built-in test runner with
testgenie test - Multiple output reporters (default, JSON, verbose, minimal)
- Coverage reporting and analysis
- Watch mode for continuous testing
- Pattern-based test filtering
Coming Soon:
- Mocha: Traditional Node.js testing framework
- Vitest: Fast Vite-native testing framework
Choose from multiple test generation styles:
describe("Calculator", () => {
describe("when adding numbers", () => {
it("should return correct sum for positive numbers", () => {
// test implementation
});
});
});suite("Calculator", () => {
test("adds positive numbers correctly", () => {
// test implementation
});
});test("Calculator.add()", () => {
// concise test implementation
});describe("Calculator utility class", () => {
it("should correctly calculate the sum of two positive integers and return the expected result", () => {
// detailed test implementation with extensive comments
});
});- No API key required
- Optimized for test generation
- Best performance and quality
# Set during init or manually
testgenie init
# Select "TestGenie API"- Models: GPT-4o, GPT-4o-mini, GPT-4-turbo
- Setup: Set
OPENAI_API_KEYenvironment variable
export OPENAI_API_KEY="your-api-key"- Models: Gemini-1.5-Pro, Gemini-1.5-Flash
- Setup: Set
GOOGLE_GENERATIVE_AI_API_KEYenvironment variable
export GOOGLE_GENERATIVE_AI_API_KEY="your-api-key"- Models: Claude-3.5-Sonnet, Claude-3-Haiku
- Setup: Set
ANTHROPIC_API_KEYenvironment variable
export ANTHROPIC_API_KEY="your-api-key"TestGenie uses testgenie.config.js in your project root:
export default {
// Test framework (Jest only for now)
framework: "jest",
// Test generation style
style: "bdd", // "bdd" | "tdd" | "minimal" | "verbose"
// Test directory
testDir: "__tests__",
// AI provider configuration
ai: {
provider: "testgenie-api", // "testgenie-api" | "openai" | "gemini" | "claude"
model: "auto", // or specific model name
},
// File patterns to include
include: ["src/**/*.{js,ts,jsx,tsx}", "lib/**/*.{js,ts,jsx,tsx}"],
// File patterns to exclude
exclude: [
"**/*.test.{js,ts,jsx,tsx}",
"**/*.spec.{js,ts,jsx,tsx}",
"**/node_modules/**",
],
// Coverage settings
coverage: {
threshold: 80, // minimum coverage percentage
includeUntested: true,
},
// Git integration
git: {
autoCommit: false,
commitMessage: "test: add generated tests",
},
// Output preferences
output: {
emojis: true,
verbose: false,
},
};| Requirement | Version | Notes |
|---|---|---|
| Node.js | 16+ | LTS recommended |
| Package Manager | npm, yarn, pnpm, or bun | Any modern package manager |
| Git | Any | Optional, for diff-based generation |
| Test Framework | Jest | Mocha/Vitest coming soon |
TestGenie automatically detects and installs missing dependencies when you run testgenie test:
For JavaScript projects:
jest,@jest/globals@testing-library/react,@testing-library/jest-dom(for React)jest-environment-jsdom(for React components)
For TypeScript projects:
@types/jest,ts-jest(additional to above)
Manual installation (optional):
# JavaScript
npm install --save-dev jest @jest/globals
# TypeScript
npm install --save-dev jest @jest/globals @types/jest ts-jest
# React projects (auto-detected and installed)
npm install --save-dev @testing-library/react @testing-library/jest-dom jest-environment-jsdom// src/utils/math.js
export function add(a, b) {
return a + b;
}
export function multiply(a, b) {
return a * b;
}Generated test:
// __tests__/src/utils/math.test.js
import { describe, it, expect } from "@jest/globals";
import { add, multiply } from "../../../src/utils/math.js";
describe("add", () => {
it("should return correct sum for positive numbers", () => {
expect(add(2, 3)).toBe(5);
});
it("should handle negative numbers", () => {
expect(add(-1, 1)).toBe(0);
});
it("should handle zero values", () => {
expect(add(0, 5)).toBe(5);
});
});
describe("multiply", () => {
it("should return correct product", () => {
expect(multiply(3, 4)).toBe(12);
});
it("should handle zero multiplication", () => {
expect(multiply(5, 0)).toBe(0);
});
});// Generated test for async functions
describe("fetchUserData", () => {
it("should fetch user data successfully", async () => {
const mockUser = { id: 1, name: "John" };
global.fetch = jest.fn().mockResolvedValue({
ok: true,
json: jest.fn().mockResolvedValue(mockUser),
});
const result = await fetchUserData(1);
expect(result).toEqual(mockUser);
expect(fetch).toHaveBeenCalledWith("/api/users/1");
});
});TestGenie automatically detects React components and generates comprehensive tests:
# Generate tests for React component
testgenie gen src/components/UserForm.tsx
# Run React tests with automatic setup
testgenie test --coverageGenerated React test with automatic imports and setup:
import { describe, it, expect, jest, beforeEach } from "@jest/globals";
import React from "react";
import { render, fireEvent, screen } from "@testing-library/react";
import { UserForm } from "../../../src/components/UserForm";
beforeEach(() => {
jest.clearAllMocks();
window.alert = jest.fn();
});
describe("UserForm", () => {
it("should submit form with valid data", () => {
const onSubmit = jest.fn();
render(<UserForm onSubmit={onSubmit} />);
fireEvent.change(screen.getByLabelText("Name:"), {
target: { value: "John Doe" },
});
fireEvent.change(screen.getByLabelText("Email:"), {
target: { value: "john@example.com" },
});
fireEvent.submit(screen.getByRole("button", { name: /Submit/i }));
expect(onSubmit).toHaveBeenCalledWith({
name: "John Doe",
email: "john@example.com",
age: "",
});
});
});Check that the file path is correct and that it's not excluded in exclude patterns in your config. Common issues include:
- File not found: Verify the file path exists and is accessible
- Excluded patterns: Check your
testgenie.config.jsexclude patterns - Unsupported file type: Ensure the file has a supported extension (
.js,.ts,.jsx,.tsx) - AI provider issues: Verify your API keys are set correctly for external providers
TestGenie includes a built-in test runner with automatic setup:
# Basic test execution
testgenie test
# With coverage reports
testgenie test --coverage
# Watch mode for development
testgenie test --watch --reporter=verboseThe test command automatically:
- Detects and installs missing Jest dependencies
- Creates optimized Jest configuration
- Sets up React Testing Library for React projects
- Configures TypeScript support when needed
Mocha and Vitest support is coming soon! Currently, only Jest is supported. We're actively working on expanding framework support:
- Jest: β Full support
- Mocha: π§ Coming soon
- Vitest: π§ Coming soon
Each provider requires different setup:
TestGenie API (Recommended):
- No setup required
- Best performance for test generation
OpenAI:
export OPENAI_API_KEY="your-api-key"Google Gemini:
export GOOGLE_GENERATIVE_AI_API_KEY="your-api-key"Anthropic Claude:
export ANTHROPIC_API_KEY="your-api-key"TestGenie supports:
- JavaScript:
.js,.jsx - TypeScript:
.ts,.tsx - React Components: Both JS and TS
- Node.js modules: CommonJS and ES modules
You can customize tests through your testgenie.config.js:
export default {
style: "bdd", // or "tdd", "minimal", "verbose"
testDir: "__tests__", // custom test directory
output: {
emojis: true, // enable/disable emojis
verbose: false, // detailed output
},
};TestGenie automatically excludes existing test files (.test.js, .spec.js, etc.) to avoid conflicts. If you want to regenerate tests, either:
- Delete the existing test file first
- Use a different output directory with
--output
TestGenie automatically detects TypeScript projects and generates appropriate tests. Ensure you have:
npm install --save-dev @types/jest ts-jestYour jest.config.js should include:
export default {
preset: "ts-jest",
testEnvironment: "node",
};- BDD: Descriptive, nested describe/it blocks
- TDD: Traditional test/suite structure
- Minimal: Concise, straightforward tests
- Verbose: Detailed with extensive comments
TestGenie uses advanced AI models specifically trained for test generation with enhanced behavioral analysis. The AI provides production-ready tests by:
Code Analysis:
- Analyzes your code structure, dependencies, and logic flow
- Understands React component validation and form behavior
- Traces async function execution and Promise handling
- Detects DOM interactions and browser API usage
Test Quality:
- Generates realistic test scenarios that match actual code behavior
- Includes comprehensive edge cases and error handling
- Follows testing best practices and framework conventions
- Creates proper mocks for FormData, console methods, and DOM elements
React & Async Expertise:
- Automatically imports React and React Testing Library for JSX components
- Handles form validation logic and user interaction flows
- Properly mocks browser APIs (window.alert, console.error)
- Understands Promise timing and rejection conditions
While tests are comprehensive and thoroughly analyzed, always review them before committing to ensure they meet your specific requirements.
Absolutely! We welcome contributions and feature requests:
- π Bug Reports: GitHub Issues
- π‘ Feature Requests: GitHub Discussions
- π€ Contributions: See our Contributing section below
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see the LICENSE file for details.
- π§ Email: support@testgenie.ai
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
Happy Testing! π§ͺβ¨