arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2408.11324cs.SE
收藏

HITS:基于方法切片的高覆盖率LLM单元测试生成

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

Zejun Wang, Kaibo Liu, Ge Li, Zhi Jin

AI总结:

针对LLM生成单元测试时难以覆盖复杂方法的问题,提出将焦点方法切片后逐片生成测试用例,显著提升行与分支覆盖率。

摘要:

大型语言模型(LLMs)在为Java项目生成单元测试方面表现良好。然而,在覆盖项目中复杂的焦点方法方面,其性能较差。复杂方法包含许多条件和循环,要求测试用例足够多样化以覆盖所有行和分支。然而,现有的基于LLM的测试生成方法将整个待测方法提供给LLM,而没有对输入分析提供辅助。LLM难以推断测试输入以覆盖所有条件,导致行和分支的遗漏。为解决该问题,我们提出将焦点方法分解为切片,并让LLM逐切片生成测试用例。我们的方法简化了分析范围,使LLM更容易覆盖每个切片中的更多行和分支。我们构建了一个数据集,包含从现有最先进方法所使用的项目中收集的复杂焦点方法。我们的实验结果表明,在行覆盖率和分支覆盖率方面,我们的方法显著优于当前基于LLM的测试用例生成方法和典型的SBST方法Evosuite。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑