Skip to main content
QUICK REVIEW

[Paper Review] Advancing Code Coverage: Incorporating Program Analysis with Large Language Models

Yang Chen, Junjie Chen|arXiv (Cornell University)|Apr 7, 2024
VLSI and Analog Circuit TestingComputer Science7 citations
TL;DR

TELPA enhances LLM-based test generation by using program-analysis-informed prompting to reach hard-to-cover branches, outperforming state-of-the-art SBST and LLM-based techniques on 27 Python projects. It combines backward object construction analysis, forward inter-procedural analysis, counter-example guidance, and feedback loops.

ABSTRACT

Automatic test generation plays a critical role in software quality assurance. While the recent advances in Search-Based Software Testing (SBST) and Large Language Models (LLMs) have shown promise in generating useful tests, these techniques still struggle to cover certain branches. Reaching these hard-to-cover branches usually requires constructing complex objects and resolving intricate inter-procedural dependencies in branch conditions, which poses significant challenges for existing test generation techniques. In this work, we propose TELPA, a novel technique aimed at addressing these challenges. Its key insight lies in extracting real usage scenarios of the target method under test to learn how to construct complex objects and extracting methods entailing inter-procedural dependencies with hard-to-cover branches to learn the semantics of branch constraints. To enhance efficiency and effectiveness, TELPA identifies a set of ineffective tests as counter-examples for LLMs and employs a feedback-based process to iteratively refine these counter-examples. Then, TELPA integrates program analysis results and counter-examples into the prompt, guiding LLMs to gain deeper understandings of the semantics of the target method and generate diverse tests that can reach the hard-to-cover branches. Our experimental results on 27 open-source Python projects demonstrate that TELPA significantly outperforms the state-of-the-art SBST and LLM-based techniques, achieving an average improvement of 31.39% and 22.22% in terms of branch coverage.

Motivation & Objective

  • Motivate the need to cover hard-to-reach branches that SBST and standard LLM prompts miss.
  • Propose TELPA, which integrates backward/forward method-invocation analyses to guide test generation.
  • Improve efficiency with counter-example sampling and a feedback-based prompting loop.
  • Demonstrate TELPA's effectiveness against Pynguin and CODAMOSA on 27 Python projects.

Proposed method

  • Perform preceding test generation using existing tools to cover easy branches.
  • Apply backward method-invocation analysis to extract object-construction sequences ending at the target method.
  • Perform forward method-invocation analysis to identify all methods affecting branch constraints.
  • Sample diverse counter-examples from existing tests to guide LLMs away from ineffective paths.
  • Incorporate program-analysis results and counter-examples into LLM prompts and use a two-stage CoT prompting approach to generate diverse tests.
  • Evaluate by comparing branch and line coverage against Pynguin and CODAMOSA on 27 Python projects.

Experimental results

Research questions

  • RQ1RQ1: How much does TELPA improve code coverage relative to state-of-the-art techniques?
  • RQ2RQ2: How do TELPA's main components (backward/forward analysis, counter-examples, feedback) affect performance?
  • RQ3RQ3: How does the choice of preceding tool (Pynguin or CODAMOSA) and LLM impact TELPA's performance?

Key findings

  • TELPA achieves average improvements of 31.39% in branch coverage over Pynguin and 22.22% over CODAMOSA within the same time budget.
  • TELPA also improves average line coverage by 15.67% over Pynguin and by a comparable margin over CODAMOSA.
  • Across 27 projects, TELPA consistently boosts coverage after the initial bottleneck of easy branches is surpassed.
  • Ablation shows backward analysis, forward analysis, counter-example sampling, and feedback each contribute to performance gains.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.