Enhancing LLM-Based Test Generation by Eliminating Covered Code

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Xu, WeiZhe, Liu, Mengyu, Kong, Fanxin
Format: Preprint
Published: 2026
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866908852414316544
author Xu, WeiZhe
Liu, Mengyu
Kong, Fanxin
author_facet Xu, WeiZhe
Liu, Mengyu
Kong, Fanxin
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2602_21997
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle Enhancing LLM-Based Test Generation by Eliminating Covered Code
Xu, WeiZhe
Liu, Mengyu
Kong, Fanxin
Software Engineering
Artificial Intelligence
Machine Learning
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.
title Enhancing LLM-Based Test Generation by Eliminating Covered Code
topic Software Engineering
Artificial Intelligence
Machine Learning
url https://arxiv.org/abs/2602.21997