Home
Relevant source files
The following files were used as context for generating this wiki page:
TestGen is an AI-powered platform designed to automatically generate and execute comprehensive test cases for code repositories. It leverages Google's Gemini AI to analyze source code and create a suite of tests, including unit, integration, edge case, and error handling scenarios. The system is comprised of a React frontend for user interaction and a backend component responsible for repository processing and communication with the AI model.
The project features two backend implementations: an original Go-based server and a newer, browser-based client-side backend. This dual approach offers flexibility in deployment, with the client-side version simplifying setup by removing the need for a separate server process. The main user interface is a dashboard that guides the user through cloning a repository, generating tests, and executing them.
Sources: README.md:3-6, testgen/CLIENT_BACKEND.md:5-10
Architecture Overview
The TestGen platform is built on a three-tier architecture: a frontend for user interaction, a backend for logic and data processing, and an external AI service for test generation.
This diagram illustrates the high-level interaction between the frontend, backend, and external services.
Sources: README.md:15-25, testgen/CLIENT_BACKEND.md:5-10
Project Structure
The repository is organized into two main directories: testgen/ for the frontend application and testgen-backend/ for the Go backend server.
| Directory/File | Description |
|---|---|
testgen/ | Contains the React + Vite + TypeScript frontend application. |
testgen/src/pages/Dashboard.tsx | The main application page with the primary user interface. |
testgen/src/lib/backend.ts | The client-side backend implementation that runs in the browser. |
testgen/src/components/TestRunner.tsx | The component responsible for executing generated test cases. |
testgen-backend/ | Contains the Go backend server. |
testgen-backend/main.go | The main entry point for the Go server, defining API endpoints. |
Sources: README.md:27-48
System Workflow
The core functionality of TestGen is divided into three main stages: Repository Analysis, Test Generation, and Test Execution.
Sources: README.md:120-128
1. Repository Analysis
This stage involves fetching and processing the source code from a user-provided GitHub repository.
This sequence shows how the application fetches repository content using the backend, which in turn calls the GitHub API.
Sources: testgen/src/pages/Dashboard.tsx:61-98, testgen/src/lib/backend.ts:211-285, testgen-backend/main.go:133-162
2. Test Generation
Once the code context is prepared, it is sent to the Gemini AI to generate test cases.
This sequence details the interaction with the Gemini API to generate tests based on the fetched code.
Sources: testgen/src/pages/Dashboard.tsx:100-137, testgen/src/lib/backend.ts:489-584, testgen-backend/main.go:402-550
3. Test Execution
The generated test cases are executed in a sandboxed environment within the browser.
This flow shows the process handled by the TestRunner component to execute tests and display results.
Sources: testgen/src/components/TestRunner.tsx:187-230
Backend Implementations
The project provides two distinct backend implementations to handle the core logic.
Go Backend (testgen-backend/)
The original backend is a server written in Go. It is responsible for cloning repositories using the git command-line tool, filtering files, generating a context file, and proxying requests to the Gemini API.
API Endpoints:
| Method | Endpoint | Request Body | Response Body | Description |
|---|---|---|---|---|
POST | /api/clone-repo | {"repoUrl": "string"} | RepoResponse | Clones a GitHub repository, processes its files, and saves a context file. |
POST | /api/generate-tests | GeminiRequest | GeminiResponse | Sends the code context to the Gemini API to generate test cases. |
GET | /api/context/{owner}/{repo} | N/A | {"context": "string"} | Retrieves the previously generated context file for a repository. |
Sources: README.md:82-118, testgen-backend/main.go:300-550
Client-Side Backend (testgen/src/lib/backend.ts)
A newer implementation runs entirely in the browser, eliminating the need for a separate Go server. It uses the GitHub REST API to fetch file contents directly, and calls the Gemini API from the client.
This diagram shows the key static methods of the ClientBackend class, which encapsulates the browser-based logic.
Sources: testgen/src/lib/backend.ts, CLIENT_BACKEND.md
This client-side approach simplifies deployment but introduces considerations such as CORS limitations with the GitHub API and the need to manage the Gemini API key on the client side.
Sources: CLIENT_BACKEND.md:21-26
Data Models
The system uses several key data structures to pass information between the frontend, backend, and external APIs.
Repository and File Interfaces
| Interface | Field | Type | Description |
|---|---|---|---|
RepoRequest | repoUrl | string | The URL of the GitHub repository to process. |
FileContent | path | string | The relative path of the file within the repository. |
content | string | The text content of the file. | |
size | number | The size of the file in bytes. | |
RepoResponse | success | boolean | Indicates if the operation was successful. |
message | string | A status message. | |
filesCount | number | The number of files processed. | |
files | FileContent[] | An array of processed files. |
Sources: testgen/src/lib/backend.ts:4-20
Gemini AI Interfaces
| Interface | Field | Type | Description |
|---|---|---|---|
GeminiRequest | apiKey | string | The user's Google Gemini API key. |
codeContext | string | The stringified code context from the repository. | |
additionalPrompt | string | Optional additional instructions for the AI. | |
GeminiTestCase | id | string | A unique identifier for the test case. |
name | string | A descriptive name for the test. | |
description | string | A detailed description of the test's purpose. | |
input | any | The input data for the function being tested. | |
expected | any | The expected output or result. | |
code | string | The function or code snippet being tested. | |
testType | string | Type of test (e.g., 'unit', 'integration'). | |
priority | string | Priority of the test (e.g., 'high', 'medium'). | |
GeminiResponse | testCases | GeminiTestCase[] | An array of generated test cases. |
summary | object | A summary of the types and counts of tests generated. |
Sources: testgen/src/lib/backend.ts:22-40
Frontend
The user interface is a single-page application built with React and managed from the Dashboard.tsx component. It features a tabbed layout to separate the main stages of the workflow.
- Generate: Allows users to input a GitHub repository URL or paste code directly. From here, they can fetch repository content and trigger the AI test generation.
- Execute: Displays the generated test cases and allows the user to run them using the
TestRunnercomponent. It shows real-time progress and status for each test. - Results: Provides a summary and visualization of the test execution results.
- Settings: A dedicated tab for users to input their Gemini API key.
The state of the application, including the repository URL, API key, fetched code, and generated test cases, is managed within the Dashboard component.
Sources: testgen/src/pages/Dashboard.tsx:43-52, 143-180
Conclusion
TestGen provides a streamlined workflow for developers to enhance their testing process. By integrating with GitHub and Google's Gemini AI, it automates the creation of diverse and comprehensive test suites. The project's architecture, with both a traditional Go backend and a modern client-side alternative, demonstrates a flexible approach to building web applications that interact with external services. The frontend provides a clear, intuitive interface for managing the entire process from code input to result analysis.
Sources: README.md:3-6, 130-141