This article describes a practical, production-ready design for an AI-based test-case generator that converts textual requirements (user stories, acceptance criteria, functional specs) into executable test cases.
We cover architecture, ER diagram, workflow/flowchart, sequence diagram, prompt engineering, sample prompts, backend and frontend examples, test output formats (NUnit / Jest / Cucumber), CI integration, data generation, verification, and production considerations.
All headings use the smaller style you requested. Language is simple Indian English and suitable from beginner to expert.
Overview
Goal: let product owners or developers paste requirements (or upload a spec) and automatically obtain:
Structured test cases (title, steps, preconditions, expected results)
Test code stubs (unit/integration/e2e) in desired framework (NUnit, xUnit, Jest, Cypress)
Test data suggestions and mock payloads
Test metadata (priority, tags, estimated runtime)
CI-ready artifacts (test files, runner config)
Main components: UI to submit requirements, a .NET backend that orchestrates GPT calls + rule-based post-processing, a test template library, a storage layer for test artifacts, and optional runner integration.
High-level architecture
[Angular UI] <--HTTPS--> [ASP.NET Core API] <--HTTPS--> [OpenAI / GPT API]
| | |
| Submit requirements | Builds prompt | Generates structured test JSON / code
| | Stores test artifacts |
v v v
Test Preview Database (SQL) Test Runner / CI
(edit & approve) - Requirements - Execute tests
- GeneratedTests
- Templates
ER Diagram (core entities)
+---------------------+ 1 → N +----------------------+
| Requirement |--------------- | GeneratedTest |
+---------------------+ +----------------------+
| RequirementId (PK) | | TestId (PK) |
| Title | | RequirementId (FK) |
| RawText | | TestTitle |
| CreatedBy | | Priority |
| CreatedAt | | Type (unit/e2e) |
+---------------------+ | Steps (JSON) |
| ExpectedResult |
| CodeSnippet (text) |
| Status (draft/approved)|
+----------------------+
Flowchart / Workflow
[User paste requirement]
↓
[UI sends to API]
↓
[API: Validate + Sanitize]
↓
[API: Build prompt (template + requirement + config)]
↓
[Call GPT API -> parse result JSON]
↓
[Post-process: normalise, validate schema, dedupe]
↓
[Store GeneratedTest in DB]
↓
[UI: Present test cases (edit / approve / export)]
↓
[Export: code stubs (NUnit / Jest / Cucumber) or pipeline artifact]
Sequence diagram (generate + approve + run)
User -> UI: Submit requirements
UI -> API: POST /api/tests/generate
API -> GPT: POST (prompt + schema)
GPT -> API: JSON response (tests)
API -> DB: Save tests
API -> UI: Return tests for preview
User -> UI: Approve / Edit test
UI -> API: POST /api/tests/{id}/approve
API -> CI: Push artifact or create pipeline job
CI -> Test Runner: Execute tests
Runner -> API: Report results
Core design principles
Structured JSON schema for generated tests (always validate).
Prompt templates stored and versioned.
Human-in-the-loop: provide editor UI so testers can refine generated cases.
Multiple output formats: stub code for NUnit, Jest, Cypress, or Gherkin.
Idempotency and deduplication (don’t create duplicate tests for same requirement).
Security: sanitize input, avoid leaking secrets to GPT prompts.
Audit: store prompt + GPT response for traceability.
Test JSON schema (example)
Use a strict schema the backend validates after GPT response.
{
"requirementId": "guid",
"tests": [
{
"testId": "guid",
"title": "Should create order with valid data",
"type": "integration", // unit | integration | e2e
"priority": "P1", // P1|P2|P3
"preconditions": ["User is authenticated", "Cart has items"],
"steps": [
"Call POST /api/orders with payload { ... }",
"Assert response 201"
],
"expectedResult": "Order created and saved with status 'New'",
"testData": {
"payload": { "customerId": 123, "items": [{ "sku": "A1", "qty": 2 }] }
},
"codeTemplates": {
"nunit": "// C# test stub here as string",
"jest": "// JS jest stub here"
}
}
]
}
Prompt engineering (practical templates)
A good prompt instructs the model to return structured JSON only (no prose). Always include a strict response schema and examples.
Minimal prompt (example)
You are a test-case generator. Input: a requirement text and desired output frameworks.
Produce only valid JSON matching the schema:
{ "tests": [ { "title": string, "type": "unit|integration|e2e", "priority": "P1|P2|P3", "preconditions": [string], "steps":[string], "expectedResult": string, "testData": object } ] }
Requirement:
"<PASTE REQUIREMENT HERE>"
Frameworks: ["nunit","jest"]
Rules:
- Use short titles.
- Provide 3 test cases: positive, negative, edge.
- Do not include any explanation.
Advanced prompt (with examples)
Provide 1–2 few-shot examples to improve structure. Keep token size in mind.
Backend: ASP.NET Core — core flow
Responsibilities
Build prompt from requirement + prompt template + configuration
Call GPT API (rate-limit / retry)
Validate response JSON against schema (Newtonsoft / System.Text.Json + JSON schema)
Store tests and prompt/response for audit
Generate code stubs from templates and test data
Provide endpoints for preview, edit, approve, export

Join the conversation! Your thoughts help the community grow.