Skip to content
| Marketplace
Sign in
Visual Studio Code>Testing>TestGen AI - Test GeneratorNew to Visual Studio Code? Get it now.
TestGen AI - Test Generator

TestGen AI - Test Generator

Roiner Camacho

| (0) | Free
Automatically generates tests using AI for hooks and utility functions
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

TestGen AI

Version VS Code Cursor License

AI-Powered Test Generator for React & TypeScript

Automatically generate comprehensive tests for your React hooks and utility functions using OpenAI GPT-4.

Install from Marketplace • Documentation • Report Bug


✨ Features

  • 🤖 AI-Powered Generation - Uses GPT-4 or GPT-3.5-turbo to generate intelligent, contextualized tests
  • 🔍 Smart Code Analysis - Automatically detects hooks and utility functions that need testing
  • ⚡ Zero Configuration - Works out of the box with basic templates, AI optional
  • 🎯 Intelligent Detection - Distinguishes between hooks and functions automatically
  • 📁 Path Alias Support - Resolves TypeScript path aliases from tsconfig.json
  • 🚫 Smart Filtering - Ignores service hooks (useQuery/useMutation wrappers)
  • 🔄 Batch Processing - Generate tests for entire projects or individual files

🚀 Quick Start

Installation

From Marketplace:

  1. Open VS Code or Cursor
  2. Press Cmd+Shift+X (Mac) or Ctrl+Shift+X (Windows/Linux)
  3. Search for TestGen AI
  4. Click Install

Or install via command:

code --install-extension RoinerCamacho.testgen-ai

First Use

  1. Open a TypeScript/TSX file (hook or utility function)
  2. Press Cmd+Shift+P (or Ctrl+Shift+P)
  3. Type: TestGen: Generate test for current file
  4. Done! Your test file is generated and opened automatically

Configure AI (Optional)

For AI-powered test generation:

  1. Get your OpenAI API key from platform.openai.com/api-keys
  2. Open Settings (Cmd+,)
  3. Search for testgen
  4. Enter your API key in testgen.openaiApiKey

Or add to settings.json:

{
  "testgen.openaiApiKey": "sk-your-key-here",
  "testgen.model": "gpt-4"
}

📖 Usage

Commands

Command Description
TestGen: Generate test for current file Generate test for the active file
TestGen: Analyze project Scan project and list files without tests
TestGen: Generate all missing tests Generate tests for all untested files

Example

Input (src/hooks/useBoolean.ts):

import { useState } from 'react'

export const useBoolean = (initialValue = false) => {
  const [value, setValue] = useState(initialValue)
  const setTrue = () => setValue(true)
  const setFalse = () => setValue(false)
  const toggle = () => setValue((v) => !v)
  return { value, setValue, setTrue, setFalse, toggle }
}

Generated Output (src/hooks/useBoolean.test.ts):

import { act, renderHook } from '@testing-library/react-hooks'
import { useBoolean } from './useBoolean'

describe('useBoolean', () => {
  it('should return initial state', () => {
    const { result } = renderHook(() => useBoolean(false))
    expect(result.current.value).toBe(false)
  })

  it('should set value to true', () => {
    const { result } = renderHook(() => useBoolean())
    act(() => {
      result.current.setTrue()
    })
    expect(result.current.value).toBe(true)
  })

  // ... more comprehensive tests generated by AI
})

⚙️ Configuration

Setting Type Default Description
testgen.openaiApiKey string "" OpenAI API key for AI-powered generation
testgen.model string "gpt-4" Model to use: "gpt-4" or "gpt-3.5-turbo"
testgen.ignoreServiceHooks boolean true Skip simple useQuery/useMutation wrappers

🎯 What Gets Tested?

✅ Detected & Tested

  • React Hooks with state (useState, useReducer)
  • Hooks with side effects (useEffect)
  • Hooks with business logic
  • Utility Functions in utils/ or funcs/ folders
  • Pure Functions with defined types

❌ Ignored

  • Service hooks (simple useQuery/useMutation wrappers)
  • Hooks without business logic
  • Non-exported functions

🛠️ Requirements

  • VS Code 1.74+ or Cursor
  • TypeScript project with tsconfig.json
  • Node.js 18+ (for development)
  • OpenAI API Key (optional, for AI generation)

📚 Documentation

  • Installation Guide - Detailed installation instructions
  • Quick Start - Get started in 5 minutes
  • Troubleshooting - Common issues and solutions
  • Publishing Guide - How to publish updates
  • Update Guide - Version management

🐛 Troubleshooting

Extension doesn't appear in commands
  1. Reload VS Code/Cursor window (Cmd+R or Ctrl+R)
  2. Verify the extension is installed and enabled
  3. Check if you're in a TypeScript project with tsconfig.json
OpenAI API key not working
  • Verify the key starts with sk-
  • Check your OpenAI account has credits
  • Ensure the key has proper permissions
  • Try regenerating the key
Tests have incorrect imports
  • Verify tsconfig.json has paths configured
  • Check path aliases are correctly set up
  • The extension attempts automatic resolution
No workspace open error

Open a folder (File → Open Folder), not just a file. The extension requires a workspace context.

For more help, see the Troubleshooting Guide.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • OpenAI for the GPT API
  • ts-morph for TypeScript analysis
  • VS Code team for the excellent extension API

Made with ❤️ for the React & TypeScript community

⭐ Star on GitHub • 📦 Marketplace • 🐛 Report Issue

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft