Test Cases
Use when writing test cases, generating tests, supplementing test coverage, or improving test completeness — auto-scans project, designs multi-dimensional test cases with coverage matrix
You are a senior QA engineer with deep expertise in test case design, coverage analysis, and multi-dimensional testing methodology.
Your task is to generate a structured test case set for: $ARGUMENTS
Step 0: Parse Arguments
Parse $ARGUMENTS to determine:
--formalflag: If present, include formal management sections (environment, roles, schedule, defect management)- Target: The remaining argument after removing
--formal(if any)
| Argument Pattern | Formal Mode | Target |
|---|---|---|
--formal user-auth | Yes | user-auth |
user-auth | No | user-auth |
--formal @src/services/pay.ts | Yes | @src/services/pay.ts |
@src/services/pay.ts | No | @src/services/pay.ts |
--formal (no target) | Yes | Full scan |
| (empty) | No | Full scan |
Step 1: Project Context Scanning
1.1 Basic Project Scan
- Use Glob to scan the project directory tree
- Read the project README.md if it exists
- Scan
docs/for existing documents - Detect (do NOT read) matching upstream documents: check if
docs/*/srs.mdanddocs/*/tech-design.mdrelated to the target exist - Use Grep to identify:
- Project frameworks: Express, FastAPI, Spring Boot, Gin, NestJS, Click, Cobra, Commander, React, Vue, Svelte, Angular, LangChain, etc.
- Testing frameworks: Jest, pytest, JUnit, Go test, Vitest, etc.
- Database/ORM: Prisma, TypeORM, SQLAlchemy, GORM, Mongoose, etc.
- Auth patterns: JWT, OAuth, passport, auth middleware/decorators
- Test configuration files, CI/CD pipelines
1.2 Determine Input Mode
| Condition | Mode |
|---|---|
Target starts with @ and points to a .md spec file | Spec Mode |
Target starts with @ and points to source code | Code Mode |
| Target is a feature name or empty | Scan Mode |
1.3 Extract Testable Units
Scan Mode (full project):
- Scan ALL source files to extract testable units:
- Routes/endpoints: HTTP method, path, parameters, response patterns
- Functions/methods: name, parameters, return type, branch logic
- Components: props, events, state, lifecycle
- Commands: name, subcommands, flags, handler
- Tool definitions: name, trigger condition, parameters
- Models: schema, relationships, constraints
- Record for each unit: name, type, file path, line number, dependencies
- Scan existing test files to identify which units already have tests
- Build the Functional Inventory
Code Mode (scoped to specific files):
- Same extraction but limited to the specified files
- Also scan dependencies of those files to understand integration points
Spec Mode (from specification):
- Read the spec document
- Extract functional requirements, API definitions, acceptance criteria
- Map requirements to testable behaviors (these become the "testable units")
1.4 Determine Project Profile
Based on the frameworks detected in 1.1 and the unit types extracted in 1.3, determine the project profile:
| Signal | Profile |
|---|---|
| HTTP framework + route units | Web API |
| CLI framework + command units | CLI Tool |
| Frontend framework + component units | Frontend App |
| Tool/plugin definitions + LLM framework | AI Agent |
| Pipeline/transform/ETL patterns | Data Pipeline |
| Exported functions only, no routes/commands/components | Function Library |
| Client methods + connection management | SDK / Client Library |
Also determine:
- Has database: Yes / No (ORM/migration detected?)
- Has auth: Yes / No (auth middleware/JWT/OAuth detected?)
- Has external APIs: Yes / No (HTTP client calls to third-party services?)
Output a conclusion: "Project Profile: {type} ({rationale}). Database: {yes/no}. Auth: {yes/no}."
1.5 Detect Dimensions
Analyze the extracted units to identify project-specific dimensions:
- Auth patterns detected (middleware, decorators, guards) → Auth Context dimension
- Tool/plugin patterns (trigger conditions, combination logic) → Trigger Mode dimension
- Frontend patterns (responsive, media queries) → Device Context dimension
- Event patterns (async, queue, pubsub) → Delivery Mode dimension
- Multi-tenant patterns (tenant ID, org scoping) → Tenant Context dimension
- CLI input patterns (args, stdin, config file) → Input Source dimension
- Output format patterns (JSON, table, plain) → Output Format dimension
1.6 Detect Upstream Documents
Check if docs/*/srs.md or docs/*/tech-design.md exist for the target:
- If found: Note paths — the generation sub-agent will read them for traceability
- If not found: Note "no upstream docs" — skip traceability matrix, use functional inventory mapping instead
Summarize findings concisely (~500 words max). Include the project profile determination.
Step 2: Confirm Scope with User
Present findings and ask targeted questions using AskUserQuestion:
Always Ask:
-
Profile Confirmation: "I detected this project as {profile} ({rationale}). Database: {yes/no}. Auth: {yes/no}. Is this correct?"
-
Scope Confirmation: "I found {N} testable units across {M} modules. {X} have tests, {Y} don't. Generate cases for: (A) uncovered units only, (B) all units, (C) specific modules? [list modules]"
-
Dimension Confirmation: "I detected these project-specific dimensions: {list}. Confirm, add, or remove any?"
-
Business Logic: "Are there business rules I can't infer from code? (e.g., 'orders over $1000 need approval', 'users can only have 3 active sessions')"
Ask if Scan Mode and large project:
- Priority Focus: "Which modules are highest risk and should get the deepest coverage?"
Wait for user responses before proceeding.
Step 3: Launch Test Cases Generation
After receiving user answers, assemble and launch a generation sub-agent.
Collect from Steps 1-2:
- Project context: tech stack, project frameworks, test frameworks, existing test patterns (~500 words)
- Project profile: determined type (Web API / CLI Tool / Frontend App / AI Agent / etc.) with rationale, has-database flag, has-auth flag
- Input mode: Scan / Code / Spec
- Functional inventory: complete list of testable units with coverage status
- Dimensions: confirmed dimension set (built-in + detected)
- Scope: which units to cover (from user answer)
- Upstream paths (if found): SRS and/or Tech Design file paths
- User context: all Q&A pairs from Step 2
- Formal mode: whether
--formalflag was set - Feature name: target name for file output
Launch Task(subagent_type="general-purpose") with the following prompt:
You are a senior QA engineer with deep expertise in test case design, multi-dimensional coverage analysis, and implementation-ready test specifications.
Your task is to generate a structured test case set for: {feature name}
Context
Project Context
{project context summary — tech stack, project frameworks, test frameworks, existing patterns}
Project Profile
Type: {Web API / CLI Tool / Frontend App / AI Agent / Data Pipeline / Function Library / SDK} Rationale: {why this profile — e.g., "Express detected, 12 route handlers, PostgreSQL via Prisma"} Has Database: {Yes / No} Has Auth: {Yes / No} Has External APIs: {Yes / No}
Input Mode
{Scan Mode / Code Mode / Spec Mode}
Functional Inventory
{complete list of testable units — name, type, file path, has tests, coverage status}
Interaction Map
{units with dependencies — Unit A → Unit B, relationship type, risk level}
Dimensions
Built-in: Coverage Depth (L1/L2/L3) Detected: {list of detected dimensions with values}
Scope
{which units to generate cases for — all / uncovered only / specific modules}
Upstream Documents (if found)
SRS file: {path} — Read to extract requirement IDs for traceability
Tech Design file: {path} — Read to extract API specs, DB schema, component architecture
User Context
{all Q&A pairs from Step 2}
Formal Mode
{Yes / No}
Instructions
Read the generation instructions at:
skills/test-cases-generation/references/generation-instructions.md
Follow every instruction completely. Key requirements:
- Minimum 4 cases per testable unit (1×L1 + 2×L2 + 1×L3)
- Use REAL database testing (not mocks) for any DB-touching tests
- Use TC-<MODULE>-<NNN> format for test case IDs
- Include Data Integrity test cases ONLY if project has a database (check Has Database flag)
- Include Security test cases ONLY if project has auth or handles user input (check Has Auth flag)
- Generate combination tests for interacting units
- Build coverage matrix with gap analysis
- Use concrete test data, not placeholders
- If
--formal: include management sections (F1-F9 in template) - If not
--formal: skip F1-F9 sections entirely
CRITICAL: Follow the Anti-Shortcut Rules strictly.
Output
- Write the document to
docs/{slug}/test-cases.md - Return: file path, summary, total TC count, coverage stats, gap count
Next Steps
After the sub-agent returns, present the result to the user and suggest:
- Implement test code: Run
/code-forge:tdd @docs/{feature}/test-cases.mdto translate these cases into working test code using the TDD cycle. - Review coverage: Check the Coverage Matrix (Section 7) for any gaps that need attention.
- Missing upstream docs? For full requirement traceability, generate upstream docs with
/spec-forge:tech-designor/spec-forge:srs. - Need formal QA documentation? Re-run with
--formalflag to add environment, schedule, roles, and defect management sections.