Skip to content

Test Generator

j0KZ edited this page Oct 9, 2025 · 3 revisions

Test Generator

Generate comprehensive test suites with edge cases and mocks.

npm version

Overview

Test Generator automatically creates comprehensive test files with edge cases, error handling, mocks, and high coverage. Supports Jest, Vitest, Mocha, and AVA frameworks.

Key Features:

  • Smart test generation - Creates complete test suites automatically
  • Edge case detection - Finds boundary conditions you might miss
  • Mock generation - Auto-creates mocks for dependencies
  • Coverage optimization - Targets high coverage with minimal tests
  • Multiple frameworks - Jest, Vitest, Mocha, AVA support

💡 How to Use

Just ask naturally in your editor - works in English and Spanish:

Generate Tests for a Function (English / Español)

"Generate tests for the calculatePrice function"
"Generar pruebas para la función calculatePrice"

"Add tests for the UserService class"
"Agregar pruebas para la clase UserService"

What You Get

 Generated 15 test cases:

📊 Test Suite Created:
  - Happy path tests: 5
  - Edge cases: 6 (zero, negative, null, undefined)
  - Error handling: 3
  - Mock setup: Complete

📈 Estimated Coverage: 95%
  - Branch coverage: 92%
  - Statement coverage: 97%
  - Function coverage: 100%

Find Missing Test Cases (English / Español)

"What test cases am I missing for login.js?"
"¿Qué casos de prueba me faltan para login.js?"

What You Get

 Missing Test Cases:

Critical:
  - Invalid email format validation
  - Expired token handling
  - SQL injection attempts

Important:
  - Rate limiting behavior
  - Concurrent login sessions
  - Session timeout handling

Nice to Have:
  - Password complexity edge cases
  - Unicode character handling

Batch Generate Tests (English / Español)

"Generate tests for all files in src/services/"
"Generar pruebas para todos los archivos en src/services/"

What You Get

 Batch Test Generation Complete:

📦 Generated Tests:
  - auth.test.ts (12 tests, 92% coverage)
  - user.test.ts (8 tests, 95% coverage)
  - payment.test.ts (15 tests, 88% coverage)
  - database.test.ts (10 tests, 90% coverage)

📊 Total: 87 tests across 12 files
📈 Average Coverage: 91%
⏱️  Time Saved: ~2 hours of manual work

🔧 Available Tools

generate_tests

Generate comprehensive test suite for a source file with edge cases and error handling.

Parameters:

  • sourceFile (required) - Path to the source file
  • config.framework (optional) - 'jest' | 'vitest' | 'mocha' | 'ava'
  • config.coverage (optional) - Target coverage percentage (default: 90)
  • config.includeEdgeCases (optional) - Include edge case tests (default: true)
  • config.includeErrorCases (optional) - Include error handling tests (default: true)

write_test_file

Generate tests and write directly to a test file.

Parameters:

  • sourceFile (required) - Path to the source file
  • testFile (optional) - Path for test file (auto-generated if not provided)
  • config (optional) - Same as generate_tests

batch_generate

Generate tests for multiple files at once.

Parameters:

  • sourceFiles (required) - Array of source file paths
  • config (optional) - Same as generate_tests

💡 Best Practices

Generate Tests Early

"Generate tests when I write this new authentication function"
"Generar pruebas cuando escribo esta nueva función de autenticación"

Target High Coverage

"Generate tests with 90% coverage for src/core/"
"Generar pruebas con 90% de cobertura para src/core/"

Use Batch Generation

"Batch generate tests for all files in src/api/"
"Generar pruebas en lote para todos los archivos en src/api/"

🔗 Related Tools

Combine with other tools for powerful workflows:


📚 Learn More


Need help? Open an issue | View documentation

Clone this wiki locally