The paper presents SymPrompt, a novel approach to generating test cases for software units using large language models (LLMs). The key insight is that the process of generating a test suite to fully cover a focal method can be broken down into a sequence of logical problems that are posed to the LLM prompts.
The approach consists of three main steps:
Collecting Approximate Path Constraints: The abstract syntax tree of the focal method is traversed to collect constraints on each possible execution path and the corresponding return values. This avoids the computational overhead of traditional symbolic execution.
Capturing Relevant Context: The type and dependency context of the focal method, including parameter types, external library calls, and class definitions, is extracted and included in the prompts to guide the model.
Generating Prompts and Tests: For each execution path, a prompt is constructed using the collected path constraints and context. The prompts are used to iteratively prompt the LLM to generate test cases targeting specific execution paths.
The evaluation shows that SymPrompt significantly improves the performance of test generation using both an open-source 16B parameter model (CodeGen2) and the large GPT-4 model. Compared to baseline prompting strategies, SymPrompt improves the ratio of correct test generations by a factor of 5 and boosts relative coverage by 26% for CodeGen2. When applied to GPT-4, SymPrompt improves coverage by over 2x.
The key benefits of SymPrompt are:
The approach overcomes limitations of traditional symbolic execution by using approximations and relying on the LLM's ability to reason about code context, while also avoiding the computational overhead of enumerating all possible execution paths.
Ke Bahasa Lain
dari konten sumber
arxiv.org
Wawasan Utama Disaring Dari
by Gabriel Ryan... pada arxiv.org 04-04-2024
https://arxiv.org/pdf/2402.00097.pdfPertanyaan yang Lebih Dalam