New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ai-testgen-tool

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai-testgen-tool

AI-powered CLI tool to generate unit, service, integration, and end-to-end tests for service codebases.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

AI-TestGen

AI-TestGen is a CLI tool that leverages AI to automatically generate unit, service, integration, and end-to-end tests for service-oriented codebases (Node.js, TypeScript, etc.).

Purpose

  • Save developer time and effort
  • Improve test coverage and quality
  • Reduce bugs and regressions
  • Standardize testing practices across teams

Features

  • Code analysis and test suggestion
  • Test code generation (unit, service, integration, E2E)
  • Customizable test templates
  • Review and edit interface
  • Integration with code editors and CI/CD
  • Flexible output directory and filename options
  • Overwrite protection and auto-directory creation
  • Dry run mode: Preview what would be generated without writing files
  • Optional LLM/AI-powered test generation: Use GPT (OpenAI) to generate tests if desired, with support for custom endpoints/gateways

Quickstart

  • Install dependencies:
    npm install
    
  • Generate tests for a TypeScript service:
    node src/cli/index.js generate --all src/userService.ts --output tests/generated
    
  • Preview what would be generated (dry run):
    node src/cli/index.js generate --all src/userService.ts --output tests/generated --dry-run
    
  • Specify custom output directories and filenames:
    node src/cli/index.js generate --all src/userService.ts \
      --unit-output tests/unit --unit-filename userService.unit.test.ts \
      --service-output tests/service --service-filename userService.service.test.ts \
      --integration-output tests/integration --integration-filename userService.integration.test.ts \
      --e2e-output tests/e2e --e2e-filename userService.e2e.test.ts
    
  • Overwrite existing files:
    node src/cli/index.js generate --all src/userService.ts --output tests/generated --force
    

LLM/AI-Powered Test Generation (Optional)

If you want to use OpenAI GPT to generate tests:

  • Set your API key:
    export OPENAI_API_KEY=sk-...
    
  • (Optional) Set a custom OpenAI-compatible base URL (for gateways, Azure, etc.):
    export OPENAI_BASE_URL=https://your-gateway.example.com/v1
    # or use the CLI flag:
    # --openai-base-url https://your-gateway.example.com/v1
    
  • Run with the --ai flag:
    node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai
    # or with a custom base URL:
    node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai --openai-base-url https://your-gateway.example.com/v1
    
  • If no API key is set, or --ai is not used, the tool falls back to static/template-based generation.
  • Each developer must use their own API key. Never share your key.

CLI Usage

Usage: ai-testgen generate [type] <target> [options]

Arguments:
  [type]         Test type: unit | service | integration | e2e (optional if --all is used)
  <target>       Target file or directory

Options:
  -o, --output <dir>           Default output directory (default: "examples")
  --all                        Generate all test types for the target file (omit [type] argument)
  --unit-output <dir>          Unit test output directory
  --unit-filename <name>       Unit test filename
  --service-output <dir>       Service test output directory
  --service-filename <name>    Service test filename
  --integration-output <dir>   Integration test output directory
  --integration-filename <name> Integration test filename
  --e2e-output <dir>           E2E test output directory
  --e2e-filename <name>        E2E test filename
  --force                      Overwrite existing test files
  --dry-run                    Show what would be generated, but do not write files
  --ai                         Use LLM-powered test generation if OPENAI_API_KEY is set
  --openai-base-url <url>      Custom OpenAI-compatible base URL (for gateways, Azure, etc.)

Real-World Examples

Preview all test types with custom locations (dry run, no [type] needed):

node src/cli/index.js generate --all src/userService.ts \
  --unit-output tests/unit --unit-filename userService.unit.test.ts \
  --service-output tests/service --service-filename userService.service.test.ts \
  --integration-output tests/integration --integration-filename userService.integration.test.ts \
  --e2e-output tests/e2e --e2e-filename userService.e2e.test.ts --dry-run

Generate all test types with OpenAI GPT (if API key is set):

export OPENAI_API_KEY=sk-...
node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai

Generate all test types with a custom OpenAI-compatible endpoint:

export OPENAI_API_KEY=sk-...
export OPENAI_BASE_URL=https://your-gateway.example.com/v1
node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai
# or
node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai --openai-base-url https://your-gateway.example.com/v1

Generate only a unit test in a custom location:

node src/cli/index.js generate unit src/userService.ts --unit-output tests/unit --unit-filename userService.unit.test.ts

Overwrite existing files:

node src/cli/index.js generate --all src/userService.ts --output tests/generated --force

Preview (dry run) before generating:

node src/cli/index.js generate --all src/userService.ts --output tests/generated --dry-run

License

MIT

Keywords

ai

FAQs

Package last updated on 10 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts