TestGen is an intelligent test generation tool that leverages Large Language Models to automatically analyze your code and generate comprehensive test suites. It uses the Grok 3 API to create both whitebox and blackbox tests for JavaScript/TypeScript functions.
- Automatic Code Analysis: Upload or paste your code to be analyzed for testable functions
- LLM-Powered Test Generation: Generate high-quality test cases using AI
- Real-time Status Updates: Monitor test generation progress
- Modern UI: Clean, responsive interface built with React and TailwindCSS
- Specification Matching: Connect code with documentation to create more accurate tests
- Test Packaging: Download generated tests as a complete package with Jest configuration
- Coverage Metrics: View detailed test coverage statistics for generated tests
TestGen follows a client-server architecture with a clear separation between the React frontend and Express.js backend:
- Frontend: Single-page application built with React and TypeScript
- Backend: Express.js server providing REST API endpoints
- Storage: File-based storage system for code, functions, and tests
- Code Analysis: Uses esprima to parse and extract functions from JavaScript/TypeScript
- Test Generation: Utilizes LLM capabilities through the Grok 3 API
- User uploads code files (.js, .ts, .jsx, .tsx) and specification files (typically README.md)
- Backend analyzes code and extracts testable functions using esprima
- Specifications are matched to functions where possible for context-aware test generation
- Test generation is queued and processed asynchronously with real-time progress updates
- Generated tests include both whitebox and blackbox methodologies for comprehensive coverage
- Tests can be viewed in the UI or downloaded as a package with proper Jest configuration
- Framework: React 18 with TypeScript
- Routing: Wouter (lightweight alternative to React Router)
- State Management: React Query for server state, React hooks for local state
- UI Components: Radix UI primitives for accessible, composable components
- Styling: TailwindCSS with custom configuration
- Form Handling: React Hook Form with Zod validation
- Framework: Express.js with TypeScript
- Code Parsing: Esprima for JavaScript/TypeScript AST generation
- File Handling: Archiver for creating downloadable zip packages
- Type Safety: TypeScript and Zod for runtime validation
- API Client: OpenAI/Grok API integration for LLM-powered test generation
- Node.js (v16+)
- npm or yarn
-
Clone the repository:
git clone https://github.com/your-username/TestGen.git cd TestGen -
Install dependencies:
npm install
-
Build the application:
npm run build
-
Start the server:
npm start
The application will be available at http://localhost:3000
To run the application in development mode with hot reloading:
npm run dev- Visit http://localhost:3000 in your browser
- Upload or paste your code into the editor
- Click "Analyze" to identify testable functions
- Click "Generate Tests" to create test cases
- Monitor the test generation progress
- View and download the generated tests
- FileDropzone: Handles file uploads with drag-and-drop capability
- FileCard: Displays uploaded files with metadata and function count
- GeneratedTestFile: Shows generated test code with syntax highlighting
- CoverageDisplay: Visualizes test coverage metrics with interactive charts
- ProcessingStatus: Provides real-time updates on test generation progress
- codeAnalyzer: Extracts functions and methods from source code
- testGenerator: Generates test cases using LLM with prioritized queue system
- grokService: Handles API interactions with the LLM provider
- storage: Manages persistence of code files, functions, and generated tests
-
POST /api/analyze: Analyze code files and identify testable functions- Request: Array of code files with content
- Response: Extracted functions with metadata
-
POST /api/generate-tests: Generate test cases for analyzed functions- Request: Array of code files with content
- Response: Initial test generation status
-
GET /api/test-status: Check the status of test generation- Response: Current progress with estimated time remaining
-
GET /api/download-tests: Download generated tests as a package- Response: ZIP file containing tests with Jest configuration
The application can be configured through environment variables:
NODE_ENV: Set toproductionfor production mode,developmentfor development modePORT: Server port (default: 3000)GROK_API_KEY: Your API key for the Grok service (if using Grok)
- Parse code using esprima to generate AST (Abstract Syntax Tree)
- Traverse AST to identify functions, arrow functions, methods, and exported functions
- Extract function signatures, parameters, and code blocks
- Match functions with specifications from documentation where possible
- Queue functions for test generation with priority for functions with specifications
- Use LLM to generate appropriate test cases based on function code and specifications
- Create both whitebox (implementation-aware) and blackbox (specification-based) tests
- Calculate estimated coverage metrics for the generated tests
- Format tests following Jest conventions with proper imports and setup
This project is licensed under the MIT License - see the LICENSE file for details.