cs.SEFeb 25, 2026

Enhancing LLM-Based Test Generation by Eliminating Covered Code

Authors: WeiZhe Xu, Mengyu Liu, Fanxin Kong

Organizations: University of Notre Dame, Notre Dame, IN, USA · Washington State University, Richland, WA, USA

Abstract

Automated test generation is essential for software quality assurance, with coverage rate serving as a key metric to ensure thorough testing. Recent advancements in Large Language Models (LLMs) have shown promise in improving test generation, particularly in achieving higher coverage. However, while existing LLM-based test generation solutions perform well on small, isolated code snippets, they struggle when applied to complex methods under test. To address these issues, we propose a scalable LLM-based unit test generation method. Our approach consists of two key steps. The first step is context information retrieval, which uses both LLMs and static analysis to gather relevant contextual information associated with the complex methods under test. The second step, iterative test generation with code elimination, repeatedly generates unit tests for the code slice, tracks the achieved coverage, and selectively removes code segments that have already been covered. This process simplifies the testing task and mitigates issues arising from token limits or reduced reasoning effectiveness associated with excessively long contexts. Through comprehensive evaluations on open-source projects, our approach outperforms state-of-the-art LLM-based and search-based methods, demonstrating its effectiveness in achieving high coverage on complex methods.

Figures & tables

Appendix figures & tables1 asset

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. Evaluating LLM-Based Test Generation Under Software Evolution

    Mar 24, 2026Sabaat Haroon, Mohammad Taha Khan, Muhammad Ali GulzarAutomated Test GenerationAutomated Software Testing

  2. Evaluating and Mitigating the Misguidance Effect of Buggy Code in LLM-Generated Unit Tests

    Jul 24, 2026Junda Zhao, Shurui Zhou, Eldan CohenLLM PromptingSpecification-Based Testing

  3. Do Coverage and Mutation Scores of LLM-Generated Test Suites Correlate with Their Effectiveness? (Replicability Study)

    Jul 24, 2026Junda Zhao, Shurui Zhou, Eldan CohenLLM EvaluationAutomated Software Testing