[Paper Review] Code-Aware Prompting: A study of Coverage Guided Test Generation in Regression Setting using LLM
SymPrompt, a code-aware multi-stage prompting framework, uses static path constraints and contextual information to guide LLMs in generating higher-coverage regression tests, outperforming baseline prompts and SBST in Python benchmarks and GPT-4.
Testing plays a pivotal role in ensuring software quality, yet conventional Search Based Software Testing (SBST) methods often struggle with complex software units, achieving suboptimal test coverage. Recent works using large language models (LLMs) for test generation have focused on improving generation quality through optimizing the test generation context and correcting errors in model outputs, but use fixed prompting strategies that prompt the model to generate tests without additional guidance. As a result LLM-generated testsuites still suffer from low coverage. In this paper, we present SymPrompt, a code-aware prompting strategy for LLMs in test generation. SymPrompt's approach is based on recent work that demonstrates LLMs can solve more complex logical problems when prompted to reason about the problem in a multi-step fashion. We apply this methodology to test generation by deconstructing the testsuite generation process into a multi-stage sequence, each of which is driven by a specific prompt aligned with the execution paths of the method under test, and exposing relevant type and dependency focal context to the model. Our approach enables pretrained LLMs to generate more complete test cases without any additional training. We implement SymPrompt using the TreeSitter parsing framework and evaluate on a benchmark challenging methods from open source Python projects. SymPrompt enhances correct test generations by a factor of 5 and bolsters relative coverage by 26% for CodeGen2. Notably, when applied to GPT-4, SymPrompt improves coverage by over 2x compared to baseline prompting strategies.
Motivation & Objective
- Motivate automated test generation in regression settings where SBST struggles with complex branches.
- Introduce a code-aware, multi-stage prompting strategy to improve test input generation via LLMs without extra model training.
- Leverage static AST analysis to extract path constraints and relevant code context to guide LLMs in generating diverse, high-coverage tests.
- Evaluate SymPrompt on a Python benchmark to quantify gains in correctness, call accuracy, and coverage across multiple LLMs.
Proposed method
- Static collection of approximate path constraints from AST traversal to represent execution paths.
- Context construction that captures type definitions and external dependencies to ground test generation.
- Iterative, path-specific prompt generation that requests tests targeting individual execution paths.
- Use of a minimum-path (basis path) set to avoid exponential path growth while preserving coverage.
- Integration with TreeSitter for parsing and compatibility with CodeGen2 and GPT-4 prompts.
- Evaluation on 897 focal methods from open-source Python projects to compare SymPrompt against SBST baselines and baseline LLM prompting.

Experimental results
Research questions
- RQ1RQ1: How does SymPrompt affect testing performance relative to simple prompting methods in regression test generation?
- RQ2RQ2: How does SymPrompt perform on projects potentially unseen in the model training data?
- RQ3RQ3: How do pathConstraint prompts and focal context contribute to performance gains?
- RQ4RQ4: Does SymPrompt improve performance on very large models such as GPT-4?
Key findings
- SymPrompt significantly improves test generation performance over baseline prompts, increasing pass and correct test generation by about 4x and 5x respectively.
- Path constraint prompts yield higher line (about 10%) and branch (about 4%) coverage improvements over baseline prompts.
- When accounting for module load effects (No-Op baseline), SymPrompt achieves about 3x greater coverage improvement (roughly 15% vs 5%).
- On CodeGen2, SymPrompt increases relative coverage by 26%; on GPT-4, it more than doubles coverage (over 2x, ~105% relative improvement).
- SymPrompt reduces focal-method invocation errors and expands coverage by guiding inputs to test additional, less-common paths (e.g., block devices, sockets).
- Baseline test generation without SymPrompt often fails to exercise complex branches, while SymPrompt enables more complete testing across diverse inputs.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.