Skip to content

About

AI-powered REST API test case generator that automatically creates positive, negative, edge-case, and validation test cases using Groq Llama 3.1. Built with React, Spring AI, Spring Boot, Java, and REST APIs.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TestPilot AI ๐Ÿš€

An AI-Powered REST API Test Case Generator

TestPilot AI is a modern developer tool designed to automate exhaustive REST API test suite creation. By providing an HTTP method, endpoint path, description, and an optional sample JSON request body, the application leverages Spring AI connected to high-speed inference on Groq Cloud (openai/gpt-oss-20b) to generate categorized positive, negative, and validation test cases with expected HTTP status mappings.


๐ŸŽฏ Project Highlights

  1. Spring AI 2.0 Integration: Built using modern Spring AI (spring-ai-starter-model-openai), utilizing Spring AI's fluent ChatClient and OpenAiChatModel configured with native JSON_OBJECT response formatting and low reasoning effort to ensure deterministic, fast JSON outputs.
  2. Stateless & Confidential Key Management: Groq API keys are supplied on-demand per request by the user via the X-Groq-Api-Key HTTP header. The backend never persists or logs keys, scoping client instances strictly to individual request lifecycles.
  3. Multi-Stage Resilient JSON Parsing: Implements a fail-safe parsing pipeline using Jackson's streaming JsonParser along with automatic regex sanitizers (recovering from stray quotes, extra trailing braces, and formatting slips) to guarantee that the UI never breaks.
  4. Postman-Inspired Dark Interface: Pure React 18 and modular Vanilla CSS designed for developer ergonomics with real-time payload tabs, status-coded badges, and instant JSON exports.
  5. Clean Layered Architecture: Follows strict separation of concerns: Controller $\rightarrow$ Orchestration Service $\rightarrow$ Spring AI Inference Layer $\rightarrow$ Global Exception Handling.

โš™๏ธ Architecture & Data Flow

1. System Architecture Diagram

flowchart TD
    subgraph Client["Frontend - React 18 & Vite"]
        UI["Postman-Style UI"]
        Modal["API Key Modal - Session Storage"]
        AxiosClient["Axios HTTP Client"]
    end

    subgraph Backend["Backend - Spring Boot & Spring AI"]
        Controller["TestCaseController - /api/testcases"]
        Validator["Jakarta Bean Validation"]
        Service["TestCaseService - Prompt & Parser"]
        LLM["LLMService - Spring AI"]
        SpringAI["OpenAiChatModel - Request Scoped"]
        Parser["Jackson Streaming JsonParser"]
        GlobalEx["GlobalExceptionHandler"]
    end

    subgraph Cloud["Groq Cloud Inference"]
        GroqAPI["Groq OpenAI-Compatible API"]
        Model["openai/gpt-oss-20b"]
    end

    UI -->|1. Submit Details and Key| AxiosClient
    AxiosClient -->|2. POST /api/testcases/generate| Controller
    Controller -->|3. Validate Payload| Validator
    Validator -->|4. Valid Request| Service
    Service -->|5. Build QA Persona Prompt| LLM
    LLM -->|6. Build OpenAiChatModel with User Key| SpringAI
    SpringAI -->|7. Execute Prompt via ChatClient| GroqAPI
    GroqAPI --> Model
    Model --> GroqAPI
    GroqAPI -->|8. Raw JSON Output| SpringAI
    SpringAI -->|9. Response String| Service
    Service -->|10. Stream Token Parse & Sanitize| Parser
    Parser -->|11. Structured TestCaseResponse DTO| Controller
    Controller -->|12. 200 OK JSON Response| AxiosClient
    AxiosClient -->|13. Render 3-Column Test Grid| UI
Loading

2. End-to-End Execution Flow

sequenceDiagram
    autonumber
    actor Dev as Developer / QA
    participant UI as React Frontend
    participant API as Spring Boot Controller
    participant Service as TestCaseService
    participant LLM as LLMService
    participant Groq as Groq Cloud API

    Dev->>UI: Enter HTTP Method, Endpoint, Description, Body
    Dev->>UI: Enter Groq API Key via Modal
    Dev->>UI: Click Generate Test Cases
    UI->>API: POST /api/testcases/generate with X-Groq-Api-Key
    API->>API: Validate Request Payload
    API->>Service: Call generateTestCases
    Service->>Service: Construct QA prompt with JSON schema
    Service->>LLM: Call generateContent with prompt and Key
    LLM->>LLM: Build OpenAiChatModel with ClientOptions
    LLM->>Groq: POST /v1/chat/completions with JSON mode
    Groq-->>LLM: Return JSON response
    LLM-->>Service: Return response string
    Service->>Service: Clean markdown fences and sanitize
    Service->>Service: Stream parse with Jackson JsonParser
    Service-->>API: Return TestCaseResponse DTO
    API-->>UI: Return 200 OK with TestCaseResponse
    UI-->>Dev: Display 3-Column Cards and Download JSON
Loading

๐Ÿ› ๏ธ Technology Stack

Backend

Technology Specification Purpose
Java 21+ Core runtime language
Spring Boot 4.x (spring-boot-starter-web) REST API container and dependency injection
Spring AI 2.0.0 (spring-ai-starter-model-openai) ChatClient fluent API, OpenAiChatModel client
Validation spring-boot-starter-validation Declarative request payload validation (@NotBlank, @Valid)
JSON Engine Jackson 2.x / 3.x (jackson-databind) Streaming JSON deserialization (JsonParser) and schema mapping
Inference Engine Groq Cloud (openai/gpt-oss-20b) Ultra-fast token generation via OpenAI-compatible endpoint
Build Tool Apache Maven 3.9+ Dependency resolution and build lifecycle management

Frontend

Technology Specification Purpose
React 18.3.1 Declarative component architecture and state management
Vite 5.3.1 Build tooling and development proxy server (/api $\rightarrow$ 8080)
Axios 1.7.2 Promise-based HTTP client with 60-second generation timeout
Vanilla CSS CSS3 Custom Properties (Variables) Postman-inspired dark developer theme
Typography Inter & JetBrains Mono Monospace code styling and readable UI typography

๐Ÿ“ Project Structure

SmartAPITester/
โ”œโ”€โ”€ backend/                               # Spring Boot Application
โ”‚   โ”œโ”€โ”€ pom.xml                            # Spring AI BOM, starters & dependencies
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ””โ”€โ”€ main/
โ”‚           โ”œโ”€โ”€ java/com/testpilot/
โ”‚           โ”‚   โ”œโ”€โ”€ TestPilotApplication.java       # Bootstrap application entry
โ”‚           โ”‚   โ”œโ”€โ”€ config/
โ”‚           โ”‚   โ”‚   โ””โ”€โ”€ CorsConfig.java             # Cross-Origin (CORS) rules
โ”‚           โ”‚   โ”œโ”€โ”€ controller/
โ”‚           โ”‚   โ”‚   โ””โ”€โ”€ TestCaseController.java     # REST endpoints (/generate, /download)
โ”‚           โ”‚   โ”œโ”€โ”€ dto/                            # Data Transfer Objects
โ”‚           โ”‚   โ”‚   โ”œโ”€โ”€ ApiRequest.java             # Incoming request payload
โ”‚           โ”‚   โ”‚   โ”œโ”€โ”€ TestCase.java               # Single scenario structure
โ”‚           โ”‚   โ”‚   โ”œโ”€โ”€ ExpectedResponse.java       # Status code prediction
โ”‚           โ”‚   โ”‚   โ””โ”€โ”€ TestCaseResponse.java       # Aggregated response structure
โ”‚           โ”‚   โ”œโ”€โ”€ exception/
โ”‚           โ”‚   โ”‚   โ”œโ”€โ”€ GlobalExceptionHandler.java # Unified error responses
โ”‚           โ”‚   โ”‚   โ””โ”€โ”€ LLMException.java           # Custom exception for AI failures
โ”‚           โ”‚   โ””โ”€โ”€ service/
โ”‚           โ”‚       โ”œโ”€โ”€ LLMService.java             # Spring AI ChatClient integration
โ”‚           โ”‚       โ””โ”€โ”€ TestCaseService.java        # QA prompt builder & stream parsing
โ”‚           โ””โ”€โ”€ resources/
โ”‚               โ””โ”€โ”€ application.properties          # Server port, Groq base URL, logging
โ”‚
โ””โ”€โ”€ frontend/                              # React 18 Application (Vite)
    โ”œโ”€โ”€ package.json                       # Dependencies & scripts
    โ”œโ”€โ”€ vite.config.js                     # Proxy forwarding /api to port 8080
    โ””โ”€โ”€ src/
        โ”œโ”€โ”€ main.jsx                       # Application bootstrap
        โ”œโ”€โ”€ App.jsx                        # Master layout, state & scrolling
        โ”œโ”€โ”€ index.css                      # Global dark theme tokens & reset
        โ”œโ”€โ”€ components/
        โ”‚   โ”œโ”€โ”€ ApiKeyModal.jsx            # Secure in-browser API key manager
        โ”‚   โ”œโ”€โ”€ InputForm.jsx              # Postman-style URL bar, method selector & tabs
        โ”‚   โ””โ”€โ”€ ResultSection.jsx          # 3-column test cards, status chips & export
        โ””โ”€โ”€ services/
            โ””โ”€โ”€ apiService.js              # Axios instance with request interceptors

๐Ÿš€ Local Setup & Execution

1. Prerequisites

  • Java JDK: 21 or higher (java -version)
  • Node.js & npm: Node 18+ and npm 9+ (node -v, npm -v)
  • Groq API Key: Free key from Groq Console

2. Start Backend (Spring Boot)

  1. Navigate to the backend directory:
    cd backend
  2. Run the application:
    mvn spring-boot:run
    The backend starts on http://localhost:8080.

3. Start Frontend (React)

  1. Open a new terminal and navigate to frontend:
    cd frontend
  2. Install dependencies:
    npm install
  3. Start the Vite development server:
    npm run dev
    The frontend starts on http://localhost:5173 with automatic API reverse-proxying.

4. Running a Test Generation

  1. Open http://localhost:5173 in your browser.
  2. Click "Set API Key" in the top navigation and paste your Groq API key (gsk_...).
  3. Select an HTTP method (e.g. POST, GET, PUT, DELETE).
  4. Enter an endpoint path (e.g. /api/v1/users).
  5. Provide a short functional description of the endpoint.
  6. (Optional) Paste a sample JSON request body in the Body tab.
  7. Click "Generate Test Cases" to view and download your full test suite.

๐Ÿ”ฎ Live Demo

๐ŸŒ Try TestPilot AI Live

๐Ÿ”ฎ Live Demo

๐ŸŒ Try TestPilot AI Live

About

AI-powered REST API test case generator that automatically creates positive, negative, edge-case, and validation test cases using Groq Llama 3.1. Built with React, Spring AI, Spring Boot, Java, and REST APIs.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages