Practical Implementation of LLMs for Automated Test Case Generation

cesar · Research & Academia · 2023 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: LLM-assisted software test-case generation

Cesar wanted to determine whether GPT-3.5 Turbo and LangChain could generate practical test cases for a real production web platform, while keeping outputs structured enough for QA use and evaluating whether AI-generated cases matched human-written test documentation quality.

Constraints:

Architecture

The implementation uses GPT-3.5 Turbo through the OpenAI API, orchestrated with LangChain, to run a three-stage prompt chain. A structured feature template is supplied feature-by-feature. The first prompt asks the model, in a QA Engineer role, to generate requirements; the second converts requirements into JSON test conditions grouped by functional or non-functional category; and the third combines the previous outputs into markdown test cases. QA engineers then blindly score AI-generated and human-written cases on correctness, consistency, and completeness and perform side-by-side A/B preferences.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  Da_tes_application["Da.tes application"] --> Feature_input_template["Feature input template"]
  Feature_input_template --> LangChain_orchestration["LangChain orchestration"]
  LangChain_orchestration --> GPT_3_5_Turbo["GPT-3.5 Turbo"]
  LangChain_orchestration --> Requirements_prompt["Requirements prompt"]
  GPT_3_5_Turbo --> Requirements_prompt
  Requirements_prompt --> Test_conditions_prompt["Test-conditions prompt"]
  GPT_3_5_Turbo --> Test_conditions_prompt
  Test_conditions_prompt --> Test_cases_prompt["Test-cases prompt"]
  GPT_3_5_Turbo --> Test_cases_prompt
  Test_cases_prompt --> AI_generated_test_cases["AI-generated test cases"]
  AI_generated_test_cases --> QA_evaluation_forms["QA evaluation forms"]
  Human_written_test_cases["Human-written test cases"] --> QA_evaluation_forms
  QA_evaluation_forms --> Evaluation_analysis["Evaluation analysis"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Da.tes application Real production web platform used as the test-case generation target. Feature input template
Feature input template Human-authored structured input containing software name, purpose, platform type, and feature description. LangChain orchestration
LangChain orchestration Manages prompt templates, context insertion, memory, and the multi-step workflow. GPT-3.5 Turbo, Requirements prompt, Test-conditions prompt, Test-cases prompt
GPT-3.5 Turbo Generates requirements, test conditions, and final test cases from prompted inputs. Requirements prompt, Test-conditions prompt, Test-cases prompt
Requirements prompt Asks the model to act as a QA Engineer and produce a requirements document. Test-conditions prompt
Test-conditions prompt Transforms requirements and the original template into JSON test conditions. Test-cases prompt
Test-cases prompt Generates markdown test cases with fields usable for test documentation. AI-generated test cases
AI-generated test cases Output artifact compared against human-written test cases. QA evaluation forms
Human-written test cases Baseline documentation produced by QA practitioners for comparison. QA evaluation forms
QA evaluation forms Blind quality scoring and A/B preference forms completed by QA volunteers. Evaluation analysis
Evaluation analysis Computes quality-factor averages and preference percentages. AI-generated test cases, Human-written test cases

Data flow

A human fills a structured template for one software feature of Da.tes. LangChain inserts that context into a QA-engineer role prompt and sends it to GPT-3.5 Turbo to produce requirements. The requirements and original template feed a second prompt that creates JSON test conditions. The template, requirements, and conditions feed a final prompt that emits markdown test cases with test steps, preconditions, expected results, data, and classification. Human QA volunteers then compare AI and human test cases through quality-factor scoring and A/B preference forms.

4 supporting quotes
“The implementation leverages the OpenAI API with GPT-3.5 Turbo as the underlying language model, orchestrated through the LangChain Python framework.”summary, stated
“The workflow consists of three main stages:”summary, stated
“The second prompt takes the output from stage one along with the original template. It generates test conditions in JSON format”summary, stated
“The final stage combines outputs from both previous stages to generate structured test cases containing title, preconditions, steps, expected results, test data, and test classification.”summary, stated

Why this architecture

The team decomposed test-case generation into intermediate prompt stages because direct generation from broad application context was too hard for GPT-3.5 Turbo. Role prompting and structured templates gave the model a QA-specific frame; JSON and markdown outputs made intermediate and final artifacts machine- and human-usable; feature-by-feature inputs reduced context overload; and blind QA scoring made the result empirical rather than anecdotal.

4 supporting quotes
“developed an interactive, multi-step approach to test case generation that breaks down the complex task into intermediate stages”summary, stated
“This design follows the chain-of-thought prompting principle, allowing the model to engage in reasoning by decomposing tasks into manageable steps.”summary, stated
“Each prompt in the pipeline employs role prompting, a technique where the model is given a specific persona”summary, stated
“The study employed a blind evaluation approach where 10 QA engineer volunteers assessed test cases”summary, stated

Models used: GPT-3.5 Turbo

Scale

Alternatives considered (roads not taken)

Generate test cases directly from a broad software description

Rejected because: The team instead decomposed the work into requirements, conditions, and cases so the model could reason through intermediate artifacts.

“developed an interactive, multi-step approach to test case generation that breaks down the complex task into intermediate stages”summary, stated
“This intermediate step helps the model "think" and analyze before producing final test cases.”summary, stated

Describe all features in one template

Rejected because: GPT-3.5 Turbo produced worse results when asked to handle multiple features in one context, so the template had to be completed separately per feature.

“the template must be completed separately for each feature in the software.”summary, stated
“Attempting to describe all features in a single template produced worse results”summary, stated

Evaluate with code coverage, execution history, and defect data

Rejected because: Those metrics were unavailable, so the researchers focused on documentation quality factors from testing literature.

“Given constraints on accessing code coverage metrics, execution history, and defect data for the Da.tes platform”summary, stated
“the researchers focused on three key documentation quality sub-factors: Correctness, Completeness, and Consistency.”summary, stated

Fully automate without human input

Rejected because: The workflow still depends on human-authored feature descriptions, and output quality depends heavily on those templates.

“The process is not fully automated and relies on human input to provide correctly formatted feature descriptions.”summary, stated
“The quality of output depends heavily on the quality of input templates.”summary, stated

Use one large template for integration tests

Rejected because: Cross-feature dependencies require bigger prompts, but larger templates correlated with degraded results.

“Integration tests require the QA engineer to explicitly describe feature interdependencies, increasing template size.”summary, stated
“However, larger templates correlated with degraded results, creating a difficult trade-off.”summary, stated

Patterns

prompt-chaining (architecture)

The workflow chains requirements generation, JSON test-condition generation, and final markdown test-case generation.

“sequential prompt chaining with intermediate outputs feeding subsequent stages is a reusable architectural pattern”summary, stated
“Stage 3 - Test Cases Generation: The final stage combines outputs from both previous stages to generate structured test cases containing title, preconditions, steps, expected results, test data, and test classification. The output is formatted in markdown for easy conversion to PDF documentation.”summary, stated

structured-output-contract (quality)

The test-condition stage uses JSON and the final stage uses a structured markdown test-case format with required fields.

“It generates test conditions in JSON format, grouping requirements by functional or non-functional categories.”summary, stated
“structured test cases containing title, preconditions, steps, expected results, test data, and test classification.”summary, stated

eval-driven-development (quality)

The study uses QA-engineer blind review and A/B comparison to evaluate generated artifacts against human-written test cases.

“The evaluation framework was designed around documentation quality factors identified in software testing literature.”summary, stated
“Similar test cases (testing the same software paths) were placed side by side, with evaluators choosing their preferred option”summary, stated

human-in-the-loop-gate (operations)

Humans provide feature templates and QA volunteers judge generated test cases, so the system augments QA rather than removing human oversight.

“Human Input Dependency: The process is not fully automated and relies on human input to provide correctly formatted feature descriptions. The quality of output depends heavily on the quality of input templates.”summary, stated
“The study employed a blind evaluation approach where 10 QA engineer volunteers assessed test cases without knowing whether they were AI-generated or human-written:”summary, stated

context-engineering (architecture)

The workflow controls model context with feature-level templates and staged intermediate outputs so GPT-3.5 Turbo sees a focused slice of the application.

“A key finding from the research was the importance of structured input for preventing hallucinations and ensuring relevant test case generation. The team developed a template through empirical experimentation that captures essential application information:”summary, stated
“This finding has important implications for production deployments, suggesting that complex applications require decomposition into feature-level inputs.”summary, stated

prompt-versioning (operations)

The research depended on empirical prompt/template iteration to find a usable input structure and staged prompting method.

“The team developed a template through empirical experimentation that captures essential application information”summary, stated
“Prompt Engineering as Development: The extensive iteration required to develop effective templates and prompts highlights that prompt engineering is a significant development effort, not a trivial configuration task.”summary, stated

Tradeoffs

Break generation into three prompt stages

Chose requirements, conditions, then cases over one-shot test-case generation.

Rationale: Intermediate stages gave GPT-3.5 Turbo a structured reasoning path and reusable outputs.

“The researchers developed an interactive, multi-step approach to test case generation that breaks down the complex task into intermediate stages.”summary, stated
“This intermediate step helps the model "think" and analyze before producing final test cases.”summary, stated

Use feature-level templates

Chose separate template per feature over one template for the whole application.

Rationale: Feature isolation improved relevance and reduced context overload, but increased operational work.

“Critically, the researchers discovered that the template must be completed separately for each feature in the software. Attempting to describe all features in a single template produced worse results, as GPT-3.5 Turbo struggled to handle multiple software features in one context.”summary, stated
“Feature Isolation Requirement: The model could not effectively handle multiple software features described in a single template. This necessitates feature-by-feature processing, which increases operational complexity.”summary, stated

Use QA documentation factors for evaluation

Chose correctness, completeness, and consistency over code-coverage or defect-history metrics.

Rationale: Those deeper operational metrics were unavailable for Da.tes, so documentation quality became the measurable proxy.

“Given constraints on accessing code coverage metrics, execution history, and defect data for the Da.tes platform”summary, stated
“These were selected based on literature identifying them as the most critical quality factors for test cases.”summary, stated

Use human blind evaluation

Chose QA engineer volunteer scoring and A/B comparison over automatic self-scoring alone.

Rationale: Human QA review made the comparison credible for documentation usefulness and preference.

“The study employed a blind evaluation approach where 10 QA engineer volunteers assessed test cases without knowing whether they were AI-generated or human-written:”summary, stated
“Form 2 - A/B Comparison: Similar test cases (testing the same software paths) were placed side by side, with evaluators choosing their preferred option and providing justification for their selection.”summary, stated

Gotchas (what bit them)

Multiple features in one prompt degraded generation quality.

Root cause: GPT-3.5 Turbo struggled to handle several software features in one context window and task frame.

Resolution: Complete the structured template separately for each feature and process the application feature-by-feature.

“GPT-3.5 Turbo struggled to handle multiple software features in one context.”summary, stated
“This finding has important implications for production deployments, suggesting that complex applications require decomposition into feature-level inputs.”summary, stated

Integration tests are hard to generate without bloating the prompt.

Root cause: Cross-feature dependencies require explicit descriptions, but larger templates degraded results.

Resolution: Treat integration coverage as a separate design problem and avoid hiding cross-feature dependency complexity inside one giant prompt.

“Integration Testing Challenges: Cross-feature dependencies proved problematic. Integration tests require the QA engineer to explicitly describe feature interdependencies, increasing template size. However, larger templates correlated with degraded results, creating a difficult trade-off.”summary, stated
“Integration Testing Challenges: Cross-feature dependencies proved problematic. Integration tests require the QA engineer to explicitly describe feature interdependencies, increasing template size. However, larger templates correlated with degraded results, creating a difficult trade-off.”summary, stated

The system was not fully automated.

Root cause: Correctly formatted feature descriptions still had to be supplied by people.

Resolution: Position the workflow as QA augmentation and template discipline, not autonomous test design.

“The process is not fully automated and relies on human input to provide correctly formatted feature descriptions.”summary, stated
“Human Input Dependency: The process is not fully automated and relies on human input to provide correctly formatted feature descriptions. The quality of output depends heavily on the quality of input templates.”summary, stated

Evaluation was limited by unavailable operational quality data.

Root cause: The researchers could not use code coverage, execution history, or defect data from the production platform.

Resolution: Use literature-backed documentation quality factors and blind QA review as a practical evaluation proxy.

“Given constraints on accessing code coverage metrics, execution history, and defect data for the Da.tes platform”summary, stated
“Given constraints on accessing code coverage metrics, execution history, and defect data for the Da.tes platform, the researchers focused on three key documentation quality sub-factors: Correctness, Completeness, and Consistency.”summary, stated

Performance varied by feature type.

Root cause: Common features such as login and signup matched familiar model priors better than unusual domain-specific functionality.

Resolution: Expect context-dependent performance variation and evaluate across feature classes, not only common workflows.

“While the model performed well with common features like login or signup, it struggled with more complex or unusual functionality”summary, stated
“In the A/B comparison, 58.6% of responses (41 of 70) preferred AI-generated test cases. Interestingly, two specific test cases showed unanimous preference for human-written versions, while one showed unanimous preference for AI-generated content, suggesting context-dependent performance variations.”summary, stated

Evaluation

The study used a blind QA evaluation with two forms. In the first, volunteers scored 10 AI-generated and 10 human-written test cases on a 1-5 scale for correctness, completeness, and consistency. In the second, similar AI and human test cases were placed side by side for A/B preference and justification. The study also reports limitations from the incomplete response count.

Metrics: Correctness score · Completeness score · Consistency score · Overall average quality score · A/B preference percentage · Number of QA volunteer responses collected

4 supporting quotes
“Form 1 - Quality Factor Scoring: Evaluators rated 10 AI-generated and 10 human-written test cases on a 1-5 scale (Very Poor to Very Good) across the three quality factors.”summary, stated
“Form 2 - A/B Comparison: Similar test cases (testing the same software paths) were placed side by side, with evaluators choosing their preferred option and providing justification for their selection.”summary, stated
“• Overall average score: AI 4.31 vs Human 4.18”summary, stated
“In the A/B comparison, 58.6% of responses (41 of 70) preferred AI-generated test cases. Interestingly, two specific test cases showed unanimous preference for human-written versions, while one showed unanimous preference for AI-generated content, suggesting context-dependent performance variations.”summary, stated

Outcomes

The study evaluated a real production web platform using a three-stage prompt workflow. Ten QA engineers were expected, seven responses were collected, evaluators scored 20 test cases in the first form, and A/B comparisons produced 70 preference responses.

5 supporting quotes
“• Overall average score: AI 4.31 vs Human 4.18”summary, stated
“In the A/B comparison, 58.6% of responses (41 of 70) preferred AI-generated test cases. Interestingly, two specific test cases showed unanimous preference for human-written versions, while one showed unanimous preference for AI-generated content, suggesting context-dependent performance variations.”summary, stated
“Qualitative feedback highlighted that AI-generated test cases excelled in writing quality, simplicity, directiveness, clarity, and completeness. These characteristics aligned with a significant percentage of participant preferences.”summary, stated
“Feature Isolation Requirement: The model could not effectively handle multiple software features described in a single template.”summary, stated
“Integration Testing Challenges: Cross-feature dependencies proved problematic. Integration tests require the QA engineer to explicitly describe feature interdependencies, increasing template size. However, larger templates correlated with degraded results, creating a difficult trade-off.”summary, stated