paperbot · PL 论文追踪

全部论文 待读 收藏

P2 HITS: High-coverage LLM-based Unit Test Generation via Method Slicing

HITS:基于方法切片的高覆盖率 LLM 单元测试生成
ASE Proceedings of the 39th IEEE/ACM International Conference on Automated Software Engineering2024匹配度 4/10 · 论文将程序切片(一种静态分析技术)用于辅助LLM生成单元测试,属于LLM与程序语言的交叉,但与用户核心关注的静态分析/形式化验证、浮点程序分析、贝叶斯程序分析以及Agentic程序分析等方向均有明显偏离。虽然其问题驱动风格和构建复杂方法数据集的做法符合用户部分偏好,但研究任务(单元测试生成)并非用户主攻领域。引用 50 inbox
Zejun Wang, Kaibo Liu, Ge Li, Zhi Jin
crossref: 2026-09-12

AI 速览

一句话:将复杂焦点方法切片后让 LLM 逐片生成单元测试,显著提升行与分支覆盖率。

LLM 在 Java 单元测试生成上表现良好,但对包含大量条件与循环的复杂焦点方法覆盖较差:现有方法将整个方法直接交给 LLM,缺少输入分析辅助,模型难以推断覆盖所有条件所需的测试输入,造成行与分支遗漏。本文提出 HITS,将焦点方法分解为切片,并让 LLM 逐切片生成测试用例,从而缩小需分析的范围,使每片中的行与分支更易被覆盖。作者从已有 SOTA 方法所使用的项目中收集复杂焦点方法构建数据集。实验表明,该方法在行覆盖率和分支覆盖率上均显著优于现有基于 LLM 的测试生成方法以及典型的基于搜索的软件测试方法 EvoSuite。

问题
现有 LLM 单元测试生成方法把完整复杂方法直接交给模型,缺乏输入分析辅助,难以推断出覆盖所有条件与循环的测试输入,导致行与分支覆盖不足。
方法
将焦点方法分解为多个切片,逐切片提示 LLM 生成测试用例,以简化分析范围并提升每片内的行与分支覆盖;同时从已有 SOTA 方法使用的项目中收集复杂焦点方法构建数据集。
评估
在自建的复杂焦点方法数据集上,与现有基于 LLM 的测试生成方法及典型 SBST 方法 EvoSuite 对比行覆盖率和分支覆盖率,结果显示本文方法显著更优。
原文摘要(Abstract)

Large language models (LLMs) have behaved well in generating unit tests for Java projects. However, the performance for covering the complex focal methods within the projects is poor. Complex methods comprise many conditions and loops, requiring the test cases to be various enough to cover all lines and branches. However, existing test generation methods with LLMs provide the whole method-to-test to the LLM without assistance on input analysis. The LLM has difficulty inferring the test inputs to cover all conditions, resulting in missing lines and branches. To tackle the problem, we propose decomposing the focal methods into slices and asking the LLM to generate test cases slice by slice. Our method simplifies the analysis scope, making it easier for the LLM to cover more lines and branches in each slice. We build a dataset comprising complex focal methods collected from the projects used by existing state-of-the-art approaches. Our experiment results show that our method significantly outperforms current test case generation methods with LLMs and the typical SBST method Evosuite regarding both line and branch coverage scores.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot8324,
  title = {HITS: High-coverage LLM-based Unit Test Generation via Method Slicing},
  author = {Zejun Wang and Kaibo Liu and Ge Li and Zhi Jin},
  booktitle = {ASE},
  year = {2024},
  doi = {10.1145/3691620.3695501}
}