A Practical Guide to Automatically Generating Test Cases from Requirements Documents

    This article explains how to build a four-stage pipeline that turns requirements documents into structured test cases with LLM agents. It covers the bottlenecks of manual test case writing, the responsibilities of each node (input, document parsing, test point extraction, test case generation, format conversion, and reply), reusable prompt skeletons, field-level structuring rules, and debugging order. It also shares general prompt engineering and quality control practices, along with the capability boundaries of automation and a machine-generation plus human-review approach for adoption.

    1. Why Test Case Writing Becomes a Bottleneck

    In most engineering teams, test case writing is the most underestimated part of the workflow. Whenever a requirements document changes, testers have to reread it, break it down line by line, and verify it repeatedly. This is both time-consuming and prone to omissions. The typical pain points fall into four areas:

    1. High information density: A requirements document often contains business rules, boundary conditions, exception flows, and compatibility requirements. Reviewing all of them manually creates a heavy cognitive load.
    2. Long transformation chain: Going from a “requirement description” to a “test point” and then to an “executable case” requires multiple rounds of abstraction and structuring, which is hard to standardize by hand.
    3. High formatting cost: Cases ultimately have to land in a table, and aligning fields, splitting steps, and describing expected results all take considerable time.
    4. Difficult consistency: Different members break down the same requirement at different levels of granularity, causing coverage and style to drift.

    Introducing a large model into this chain is not about replacing testers. It is about handing repetitive structuring work to an automated flow so that people can focus on risk judgment and business insight.

    2. Overall Approach: A Four-Stage Pipeline

    Regardless of the specific product form, this kind of solution can be abstracted architecturally into a four-stage pipeline:

    • Stage 1: Input acquisition. Receive the requirements document and normalize its format.
    • Stage 2: Requirement parsing. Extract the text content and identify functional points and constraints.
    • Stage 3: Test point extraction. Convert business semantics into verifiable check items.
    • Stage 4: Case generation and export. Fill in steps and expected results, and output a table file.

    On an agent-building platform that supports visual orchestration, this pipeline is typically implemented as a directed acyclic graph: start node → document parsing node → LLM node → LLM node → format conversion node → reply node. Each segment has a single responsibility, which makes it easy to debug and replace individually.

    3. Key Node Design in Detail

    3.1 Start Node and Input Contract

    The start node is responsible for defining the “input contract.” It is recommended to explicitly define two types of input:

    • File input: Carries the requirements document for consumption by downstream parsing nodes.
    • Query input: Carries the user’s supplementary instructions, for example “cover only the login module” or “focus on verifying permission boundaries.”

    The value of a clear input contract is that all downstream nodes can reference unified variables, avoiding field misalignment. At the same time, users can add constraints in natural language without modifying the flow structure.

    3.2 Document Parsing Node: Turning Binary into Reasonable Text

    Requirements documents are mostly a mix of rich text and tables, so extraction and cleaning are needed first. The parsing node should focus on three things:

    • Body extraction: Remove noise such as headers, footers, tables of contents, and watermarks.
    • Structure preservation: Preserve heading levels and list order as much as possible, because hierarchy often corresponds to functional module divisions.
    • Length governance: Split overly long documents into segments to avoid information truncation caused by exceeding the context window.

    A schematic pseudocode representation of its contract:

    1. parse(file) -> {
    2. title: string,
    3. sections: [{ level: int, heading: string, text: string }],
    4. raw_length: int
    5. }

    3.3 The First LLM Node: From Requirements to Test Points

    The task of this node is not to write cases, but to build a checklist. A high-quality prompt should contain four elements:

    1. Role setting: You are a senior test designer familiar with equivalence classes, boundary values, scenario methods, and state transitions.
    2. Input declaration: The context is the document parsing result, and the user instructions are supplementary constraints.
    3. Output constraints: Return a layered list, with functional modules at the first level and test points at the second level. Each test point must be verifiable.
    4. Prohibitions: Do not fabricate business rules that do not appear in the requirements.

    A reusable prompt skeleton is as follows:

    1. You are a senior test designer.
    2. 【Requirements】{{parse.text}}
    3. 【User Input】{{sys.query}}
    4. Please output a test point checklist with the following requirements:
    5. 1. Organize by functional module in layers, with module names taken from the requirement heading levels;
    6. 2. Each test point must include: ID, source requirement item, and verification target;
    7. 3. Cover the normal flow, boundary values, exception flows, permissions, and compatibility;
    8. 4. Do not fabricate rules not mentioned in the requirements; if ambiguity exists, list it separately under "Items to Confirm."

    Explicitly modeling “items to confirm” is a key design for improving the credibility of the solution. It externalizes the model’s uncertainty into a list that the team can review, rather than disguising it as a definite conclusion.

    3.4 The Second LLM Node: From Test Points to Executable Cases

    The second node takes the test point checklist and expands it into complete cases. What this stage needs most is field-level structuring constraints; otherwise, the output is hard to drop directly into a table. It is recommended to define fixed columns:

    Field Description
    Case ID Maintains a traceable mapping to the test point ID
    Module Corresponds to the requirement hierarchy
    Preconditions Data, account, and configuration state
    Steps Ordered, one action per step
    Expected result Observable and determinable
    Priority High / Medium / Low

    Two hard constraints should be added to the prompt. First, steps must be atomic; compound descriptions like “complete login and enter the homepage” are prohibited. Second, expected results must be observable; undecidable statements like “smooth experience” should be avoided.

    3.5 Format Conversion Node: From Markdown to a Table File

    Large models are naturally good at outputting structured text, so having the model produce table syntax and then rendering it into a table file at the conversion node is the lowest-cost combination. The process requires:

    • Switch to the tool view in the orchestration canvas, then search for and install a “structured text to table file” type plugin;
    • The plugin can only be referenced as a node in the flow after installation is complete;
    • Bind the input variable to the text output of the previous node, with the output being a downloadable file object.

    If the table syntax has an inconsistent number of columns, the conversion step will usually throw an error or drop columns. A more robust approach is to require in the prompt that “each row must be separated by the same number of vertical bars, and empty cells must not be omitted.”

    3.6 Reply Node and File Delivery

    The end node is responsible for delivering the file to the user. File upload/download capability needs to be enabled, and the file output of the conversion node should be bound to the reply content. During debugging, it is recommended to verify in the following order:

    1. Upload only the document without filling in supplementary instructions, and confirm the baseline output is usable;
    2. Add a module-limiting instruction and confirm the scope converges as expected;
    3. Add an “add exception scenarios” instruction and confirm incremental generation does not break existing IDs;
    4. Download the table file and check column completeness and ID traceability.

    4. General Experience in Prompt Engineering and Quality Control

    • Two-stage design beats one-stage design: Test points first, then cases. The intermediate artifact can be reviewed and reused, and it also makes it easier to locate which layer a quality problem occurs in.
    • Consistent numbering: Test points and cases share a numbering system, forming bidirectional traceability, so reviewers can quickly identify coverage gaps.
    • Make ambiguity explicit: Force the model to output items to confirm, moving risk forward to the requirement review stage.
    • Lower the temperature parameter: Structured generation scenarios should reduce randomness and prioritize format stability.
    • Allow fallback on failure: Each LLM node should retain its raw output, making it easy to rerun without redoing the entire chain.

    5. Capability Boundaries and Adoption Recommendations

    The boundaries of automation must be clearly understood: the model is good at enumeration and structuring, but it does not grasp implicit rules in the business context, nor can it replace the prioritization of risk. Therefore, a dual-track mechanism of “machine generation + human review” is recommended, treating automated output as a high-quality first draft, with the test lead filling in business constraints and regression strategy.

    For engineering adoption, the chain can be packaged as an agent shared across the team, with unified prompt templates and field specifications. General capabilities such as document parsing and format conversion can rely on general-category services on a cloud platform. For example, object storage can be used for document archiving, a log service for chain tracing, and monitoring and alerting for anomaly detection. This keeps the flow observable and gives the solution a foundation for continuous evolution.

    In summary, breaking test case writing into a four-stage pipeline of “parse, extract, generate, export” and linking it with strict structuring contracts can significantly compress writing time without sacrificing controllability, allowing the test team to return their energy to the quality decisions that truly require human judgment.