Generating Test Cases Is Not the Same as Testing AI Agents

    This article explains why evaluating AI agents requires more than checking generated test cases. Because a model call is stateless and depends on system prompts, tools, history, context, and user instructions, a single request can trigger a multi-step execution chain. The article breaks down this chain and introduces a five-layer testing approach covering results, traces, permissions, recovery, and state consistency. It also provides a practical YAML-based validation method to help readers move from simply using AI tools to designing reliable, auditable tests for agent behavior.

    In AI coding tools, entering a requirement and receiving test cases may look like a simple question-and-answer exchange. In practice, it is a multi-step execution chain. Models are typically treated as stateless functions whose output depends on the system prompt, available tools, conversation history, context, and user instructions. Tool execution, permission checks, and result injection are all maintained by the surrounding runtime.

    As a result, agent testing cannot focus only on whether the generated test case text is correct. It must also verify planning, tool parameters, permission boundaries, failure recovery, and state consistency. This article reframes that understanding and presents a layered testing method to help readers move from “knowing how to use tools” to “knowing how to test agents.”

    1. The Problem Is the Process, Not the Output

    When many teams evaluate AI coding tools, they focus only on the final output: whether there are enough test cases, whether the format is consistent, and whether normal flows are covered. This acceptance approach works for traditional template generation, but it is not enough to describe agent behavior.

    The defining characteristic of an agent is that it makes multiple decisions around a goal and may call external capabilities to read documents, retrieve knowledge, write files, or trigger workflows.

    Therefore, the same requirement can lead to different paths and results under different contexts. If testing compares only the final text, it misses risks along the path: whether unauthorized data was accessed, whether conclusions were fabricated after a tool failure, or whether intermediate results were mistaken for final facts. What truly needs to be verified is whether the “goal-plan-action-observation-correction” loop is reliable.

    2. Reconstructing the Execution Chain with a Stateless Model View

    The industry often abstracts a single model call as:

    1. output = Model(system_prompt + tools + history + context + user_instruction)

    This expression highlights that the model itself does not store progress; continuity is injected by the product-side state layer. A single “generate test cases” request involves at least the following steps:

    1. The model proposes a tool call request based on the current context;
    2. The runtime validates parameters, permissions, and executability;
    3. The tool accesses documents, meeting notes, or code repositories and returns structured results;
    4. The execution result is written into the context as a new observation;
    5. The model decides whether to continue calling tools or output a conclusion based on the updated context.

    Testing must cover every hop, not just the last one. For example, when a requirement comes from an online document, the system must first complete connector authorization and content retrieval; when the input is meeting notes, it must first load the transcribed text and locate relevant segments. A failure at any step can strip subsequent test cases of their factual basis.

    3. Five Layers of Agent Testing

    1. Result Layer: Are the Test Cases Usable?

    Check coverage, executability, clarity of expected results, and whether boundary conditions are missed. This layer is necessary but not sufficient.

    2. Trace Layer: Are the Decisions Reasonable?

    Record the reasoning summary, tool selection, parameters, and return status of each step. Verify whether there are detours, repeated calls, or irrelevant retrievals.

    3. Permission Layer: Are the Boundaries Held?

    Verify least privilege, tenant isolation, and masking of sensitive fields, as well as whether access stops after being denied instead of guessing.

    4. Recovery Layer: Are Failures Controllable?

    Simulate timeouts, rate limiting, empty results, and malformed formats. Observe whether retries have limits, whether the system degrades gracefully, and whether uncertainty is communicated to the user.

    5. State Layer: Is the Context Consistent?

    After multiple rounds of requirement changes, check whether old constraints are correctly overridden, whether progress can be recovered, and whether key facts are lost in long conversations.

    4. Practical Validation Methods

    It is recommended to build a triple of “input snapshot + expected trace + allowed deviation” for each test objective. An example is shown below:

    1. case:
    2. goal: Generate boundary test cases from a requirements document
    3. inputs:
    4. doc_ref: sandbox://req/1024
    5. constraints: [read-only, masked]
    6. expected_trace:
    7. - fetch_document
    8. - extract_requirements
    9. - generate_cases
    10. assertions:
    11. - no_write_tool_called
    12. - coverage_includes_boundary
    13. - failure_message_on_timeout

    During execution, record both the final artifact and the trace log, and set assertions at key nodes. For uncertain outputs, require the source of evidence and a confidence note; for tool failures, require explicit errors rather than silent completion. During regression, fix randomness, model version, and prompt version to avoid mistaking fluctuations for defects.

    5. From Tool User to Test Designer

    Knowing how to use generation capabilities only means you have mastered the entry point. Understanding agent testing means being able to set boundaries for autonomy. Readers can start with three practices: first, list “process observability” as an acceptance criterion; second, create dedicated test cases for permissions and failure paths; third, incorporate state consistency into multi-round regression. Only in this way can AI capabilities be used under controllable and auditable conditions, rather than being misled by a smooth interface.