AI-powered unit test generator - zero config, works with all AI IDEs. Supports Jest, xUnit, NUnit and more.
npm install testgen-ai-cliAI-powered unit test generator - zero config, works with all AI IDEs
Generate comprehensive unit tests using AI assistants (Cursor, VS Code + Copilot, JetBrains, etc.) with framework-specific prompts for Jest, xUnit, NUnit, and more.
``bashInstall
npm install -D @testgen/ai
Features
- ✅ Zero Configuration: Works out of the box with smart defaults
- ✅ Lightweight: < 5MB package size
- ✅ Universal: Works with all AI IDEs (Cursor, VS Code + Copilot, JetBrains, Codeium, etc.)
- ✅ Auto-Detection: Automatically detects project type and testing framework
- ✅ Multi-Framework: Supports Jest, xUnit, NUnit, Vitest, Mocha, Jasmine
- ✅ Detailed Prompts: Framework-specific prompts with best practices and examples
- ✅ Smart Defaults: No config file needed unless you want customization
Installation
`bash
npm install -D @testgen/ai
npx testgen-init
`That's it! The package will:
- Auto-detect your project type (React, Node.js, .NET, etc.)
- Auto-detect your testing framework (Jest, xUnit, NUnit, etc.)
- Create test directories
- Configure everything automatically
Usage with AI IDEs
$3
Works identically in all AI IDEs (Cursor, VS Code + Copilot, JetBrains AI, Codeium, etc.):
`
Using @testgen/ai prompts, generate unit tests for ComponentName
``
Using the Jest + React test generation prompt from @testgen/ai, generate unit tests for:
- Component: UserProfile
- Source File: src/components/UserProfile.tsx
- Test scenarios: Component renders, handles user interactions, displays errors
`$3
`
Using @testgen/ai Jest + React prompt, generate unit tests for:
- Component: UserProfile
- Source File: src/components/UserProfile.tsx
- Test scenarios:
- Component renders with user data
- Component handles edit button click
- Component displays error message on API failure
`$3
`
Using @testgen/ai Jest Node.js prompt, generate unit tests for:
- Function: calculateTotal
- Source File: src/utils/calculator.ts
- Test scenarios:
- Function calculates total correctly
- Function handles empty array
- Function throws error for invalid input
`$3
`
Using @testgen/ai xUnit .NET prompt, generate unit tests for:
- Class: UserService
- Source File: Services/UserService.cs
- Test scenarios:
- GetUserById returns user for valid ID
- GetUserById throws NotFoundException for invalid ID
- CreateUser creates user successfully
`CLI Commands
`bash
Initialize (one-time setup)
npx testgen-initGenerate test prompts
npx testgen-generate jest-react # Show Jest + React prompt
npx testgen-generate jest-node # Show Jest Node.js prompt
npx testgen-generate xunit # Show xUnit .NET prompt
npx testgen-generate # Auto-detect and show promptRun tests (helper command)
npx testgen-run # Shows how to run tests
`Supported Frameworks
$3
- ✅ Jest - React components and Node.js functions
- ✅ xUnit - .NET classes and methods$3
- ✅ NUnit - .NET testing
- ✅ Vitest - Fast Vite-native unit testing
- ✅ Mocha - Flexible JavaScript testing
- ✅ Jasmine - Behavior-driven JavaScript testingProject Detection
The package automatically detects:
- Project Type: React, Vue, Angular, .NET, Node.js
- Testing Framework: Jest, Vitest, xUnit, NUnit, Mocha, Jasmine
- Test Directory:
__tests__, tests, Tests, etc.
- IDE: Cursor, VS Code, JetBrains, CodeiumConfiguration (Optional)
The package works with zero configuration. A config file is only needed for customization:
`javascript
// testgen.config.js (optional)
export default {
projectType: 'react',
testingFramework: 'jest',
testDirectory: './__tests__',
sourceDirectory: './src',
};
`IDE Support
$3
- Auto-detected
- Prompts work immediately
- No configuration needed$3
- Auto-detected
- Use prompts in Copilot Chat
- No configuration needed$3
- Auto-detected
- Use prompts in AI Assistant
- No configuration needed$3
- Uses VS Code configuration
- Works with Codeium extension
- No configuration needed$3
- Prompts work universally
- Copy prompts from npx testgen-generate
- No configuration neededAvailable Prompts
Prompts are located in
prompts/universal/:
- jest-react.md - Jest + React Testing Library
- jest-node.md - Jest for Node.js
- xunit-dotnet.md - xUnit for .NET
- nunit-dotnet.md - NUnit for .NET
- vitest.md - Vitest
- README.md - Usage documentationRequirements
- Node.js 20+
- TypeScript (optional, peer dependency)
- Testing framework installed in your project (Jest, xUnit, etc.)
How It Works
1. Install the package:
npm install -D @testgen/ai
2. Initialize: npx testgen-init (auto-detects everything)
3. Use Prompts: Reference prompts in your AI IDE
4. Generate Tests: AI generates comprehensive unit tests
5. Run Tests: Use your framework's test runnerExamples
$3
`typescript
// Generated by AI using @testgen/ai prompts
import { render, screen, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { UserProfile } from './UserProfile';describe('UserProfile', () => {
test('should render with user data', () => {
render( );
expect(screen.getByText('John')).toBeInTheDocument();
});
test('should handle edit button click', async () => {
const user = userEvent.setup();
render( );
const editButton = screen.getByRole('button', { name: /edit/i });
await user.click(editButton);
expect(screen.getByRole('textbox')).toBeInTheDocument();
});
});
`$3
`csharp
// Generated by AI using @testgen/ai prompts
using Xunit;
using Moq;namespace Tests
{
public class UserServiceTests
{
private readonly Mock _mockRepository;
private readonly UserService _sut;
public UserServiceTests()
{
_mockRepository = new Mock();
_sut = new UserService(_mockRepository.Object);
}
[Fact]
public void GetUserById_WithValidId_Should_ReturnUser()
{
// Arrange
var userId = 1;
var expectedUser = new User { Id = userId, Name = "John" };
_mockRepository.Setup(x => x.GetById(userId)).Returns(expectedUser);
// Act
var result = _sut.GetUserById(userId);
// Assert
Assert.Equal(expectedUser, result);
}
}
}
`License
MIT
Support
- Documentation: See
prompts/universal/README.md` for prompt usage