AI-Driven Test Case Generation: Efficiency Practices

    This article explains how to improve the efficiency of AI-driven test case generation through engineering practices rather than relying on a stronger model alone. It covers shifting dependency validation to page load time, consolidating prompts and model settings in one configuration center, configuring generation behavior such as streaming output and AI review, enhancing input with Markdown requirement documents, and layering prompts by responsibility. It also suggests a rollout order and metrics for measuring results.

    1. Problem Background: Why AI Test Case Generation Often Fails on the First Click

    When a testing team first introduces AI-assisted test case writing, the most common complaint is not that the generated quality is poor, but that the feature does not run at all. Typical symptoms include errors appearing immediately after clicking Generate on the test case generation page, vague messages that leave users unsure whether the model, prompt, or behavior policy is missing, and configuration entries scattered across multiple locations that force first-time users to move back and forth between two or three pages.

    From an engineering perspective, the root cause of these problems is missing dependency validation. AI test case generation is actually a chain with multiple dependencies: the case-writing model, the case-review model, the writing prompt, the review prompt, and the generation behavior policy. If any link is missing or disabled, the chain breaks. Placing validation after the Generate click means configuration errors are deferred to the most expensive moment to surface.

    Therefore, the first step in efficiency optimization is not switching to a stronger model, but shifting validation left so that errors are detected during page load and users are guided to fix them.

    2. Configuration Preflight: Shift Validation to Page Load

    The recommended approach is to run an automatic dependency check every time the test case generation page is entered or refreshed. The checks should cover at least three categories:

    • Model availability: whether the case-writing model and the case-review model are configured and enabled;
    • Prompt completeness: whether the writing prompt and the review prompt exist and are non-empty;
    • Behavior policy validity: whether the generation behavior configuration has been set.

    If any item is not satisfied, a guided dialog should appear that clearly states what is missing and provides a Go to Configuration button that navigates directly to the relevant configuration page. When all checks pass, the user is not interrupted. The value of this design is turning trial-and-error troubleshooting into one-time guidance, shortening the new user path from repeated errors and searching for entry points to reading the prompt, clicking the link, and completing configuration.

    The validation logic can be abstracted as follows:

    1. REQUIRED_CHECKS = [
    2. ("case_model", is_model_configured_and_enabled),
    3. ("review_model", is_model_configured_and_enabled),
    4. ("case_prompt", is_prompt_non_empty),
    5. ("review_prompt",is_prompt_non_empty),
    6. ("gen_behavior", is_behavior_configured),
    7. ]
    8. def preflight():
    9. missing = [key for key, check in REQUIRED_CHECKS if not check()]
    10. return missing # if non-empty, render the guidance dialog

    3. Configuration Consolidation: Manage Prompts and Models in One Place

    An early common design was to configure models in the configuration center and prompts on front-end pages. This looks flexible, but it actually splits one complete configuration into two mental burdens. A more reasonable approach is configuration consolidation: place the writing prompt and the review prompt under AI test case generation in the configuration center, alongside the model configuration.

    Consolidation brings three direct benefits. First, configuration items are centralized, reducing audit and backup costs. Second, during version upgrades, Load Default Prompts can quickly reset them, avoiding mismatches between old prompts and new generation logic. Third, permission management becomes clearer, since prompts are team-level assets and are not suitable for personal operation pages.

    It is worth noting that after an upgrade, if custom prompts already exist locally, it is advisable to back them up before deleting them and reloading the default version, preventing conflicts between historical prompts and the behavior policy of the new chain.

    4. Generation Behavior Configuration: Streaming Output and AI Review Toggle

    The generation behavior configuration declares how generation happens and includes at least two switches:

    1. Default output mode: real-time streaming output or full output. Full output was the only mode in the early stage, requiring users to wait until all content was generated before seeing results, which made waiting noticeable for long requirement documents. Streaming output continuously returns content incrementally, significantly advancing time to first byte, so users can judge whether the direction is correct during generation and interrupt in time.
    2. AI review toggle: whether to automatically trigger the review model to recheck test cases after generation. Enabling it can improve coverage and compliance but increases overall time and model calls, making it suitable for critical modules; disabling it is faster and suitable for quickly producing drafts.

    The combination of behavior configuration and front-end free selection is recommended as follows: the configuration center defines default values, and the front-end page allows users to override them per run. This keeps the team baseline consistent while preserving flexibility for a single task.

    5. Input Enhancement: Markdown Requirement Document Upload

    The upper limit of generation quality is determined by the input. Supporting uploads of requirement documents in Markdown format has more advantages than pasting plain text into a text box: heading levels can map to functional module levels, lists and tables can map to steps and expected results, and code blocks can preserve structured information such as API fields.

    On the prompt side, the model can be explicitly required to use the document structure, for example:

    1. Split test targets according to the heading levels of the requirement document;
    2. Output test cases for each leaf node, with fields: title, preconditions, steps, expected results, priority;
    3. Mark content that cannot be inferred from the document as "to be confirmed"; do not fabricate.

    “Do not fabricate; mark unknowns as to be confirmed” is a key constraint for controlling hallucination and also gives the review stage a basis for judgment.

    6. Prompt Layering: Writing, Review, and Enhancement Prompts

    Splitting prompts by responsibility into four types can significantly reduce mutual interference: the writing prompt is responsible for producing structure; the review prompt is responsible for finding faults by dimension; the generation method enhancement prompt adds domain methods (such as equivalence classes, boundary values, scenario-based testing, and state transition); and the review method enhancement prompt adds review perspectives (such as coverage, executability, assertion clarity, and data preparation cost).

    The benefit of separating responsibilities is independent iteration: when only adjusting review strictness, there is no need to touch the writing logic, making A/B comparison and regression testing easier.

    7. Rollout Recommendations and Metrics

    The recommended rollout order is: first complete configuration consolidation and preflight validation, then enable streaming output, and finally run AI review in a small-scale canary release. Metrics can focus on four items: configuration-related error rate, time to first byte, manual rework rate per generation, and post-review test case adoption rate.

    In summary, efficiency improvement in AI test case generation does not depend on single-point model capability, but is an engineering result of the combined effects of shifting validation left, configuration consolidation, configurable behavior, structured input, and prompt layering. If you already use large model services from Baidu AI Cloud, it is also recommended to organize configuration and processes according to the general pattern above to obtain a stable and reusable generation experience.