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:

  1. --formal flag: If present, include formal management sections (environment, roles, schedule, defect management)
  2. Target: The remaining argument after removing --formal (if any)
Argument PatternFormal ModeTarget
--formal user-authYesuser-auth
user-authNouser-auth
--formal @src/services/pay.tsYes@src/services/pay.ts
@src/services/pay.tsNo@src/services/pay.ts
--formal (no target)YesFull scan
(empty)NoFull scan

Step 1: Project Context Scanning

1.1 Basic Project Scan

  1. Use Glob to scan the project directory tree
  2. Read the project README.md if it exists
  3. Scan docs/ for existing documents
  4. Detect (do NOT read) matching upstream documents: check if docs/*/srs.md and docs/*/tech-design.md related to the target exist
  5. 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

ConditionMode
Target starts with @ and points to a .md spec fileSpec Mode
Target starts with @ and points to source codeCode Mode
Target is a feature name or emptyScan Mode

1.3 Extract Testable Units

Scan Mode (full project):

  1. 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
  2. Record for each unit: name, type, file path, line number, dependencies
  3. Scan existing test files to identify which units already have tests
  4. 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:

SignalProfile
HTTP framework + route unitsWeb API
CLI framework + command unitsCLI Tool
Frontend framework + component unitsFrontend App
Tool/plugin definitions + LLM frameworkAI Agent
Pipeline/transform/ETL patternsData Pipeline
Exported functions only, no routes/commands/componentsFunction Library
Client methods + connection managementSDK / 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:

  1. Profile Confirmation: "I detected this project as {profile} ({rationale}). Database: {yes/no}. Auth: {yes/no}. Is this correct?"

  2. 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]"

  3. Dimension Confirmation: "I detected these project-specific dimensions: {list}. Confirm, add, or remove any?"

  4. 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:

  1. 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:

  1. Project context: tech stack, project frameworks, test frameworks, existing test patterns (~500 words)
  2. Project profile: determined type (Web API / CLI Tool / Frontend App / AI Agent / etc.) with rationale, has-database flag, has-auth flag
  3. Input mode: Scan / Code / Spec
  4. Functional inventory: complete list of testable units with coverage status
  5. Dimensions: confirmed dimension set (built-in + detected)
  6. Scope: which units to cover (from user answer)
  7. Upstream paths (if found): SRS and/or Tech Design file paths
  8. User context: all Q&A pairs from Step 2
  9. Formal mode: whether --formal flag was set
  10. 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

  1. Write the document to docs/{slug}/test-cases.md
  2. 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:

  1. Implement test code: Run /code-forge:tdd @docs/{feature}/test-cases.md to translate these cases into working test code using the TDD cycle.
  2. Review coverage: Check the Coverage Matrix (Section 7) for any gaps that need attention.
  3. Missing upstream docs? For full requirement traceability, generate upstream docs with /spec-forge:tech-design or /spec-forge:srs.
  4. Need formal QA documentation? Re-run with --formal flag to add environment, schedule, roles, and defect management sections.