arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2412.18843cs.SE
收藏

使用大型语言模型提升自动生成测试的可读性

Improving the Readability of Automatically Generated Tests using Large Language Models

Matteo Biagiola, Gianluca Ghislotti, Paolo Tonella

AI总结:

本文提出结合搜索式测试生成的高覆盖率与 LLM 的可读性优势,在保持语义和覆盖率不变的前提下改进测试与变量命名,实验证明其稳定且可读性接近人工测试。

摘要:

基于搜索的测试生成器能够有效生成具有高覆盖率的单元测试。然而,这类自动生成的测试缺乏有意义的测试名称和变量名称,导致开发者难以理解和解读。另一方面,大型语言模型(LLM)能够生成可读性很高的测试用例,但其在所实现的代码覆盖率方面,无法匹敌基于搜索的生成器的有效性。在本文中,我们提出将基于搜索的生成器的有效性与 LLM 生成测试的可读性相结合。我们的方法聚焦于改进基于搜索的工具所生成的测试名称和变量名称,同时保持其语义(即其覆盖率)不变。我们在九个工业级和开源 LLM 上的评估表明,我们的可读性提升转换总体上能够保持语义,并且在多次重复中保持稳定。此外,一项由十名专业开发者参与的人工研究表明,无论采用何种 LLM,经我们的 LLM 改进后的测试在可读性上都与开发者编写的测试相当。

英文摘要:

Search-based test generators are effective at producing unit tests with high coverage. However, such automatically generated tests have no meaningful test and variable names, making them hard to understand and interpret by developers. On the other hand, large language models (LLMs) can generate highly readable test cases, but they are not able to match the effectiveness of search-based generators, in terms of achieved code coverage. In this paper, we propose to combine the effectiveness of search-based generators with the readability of LLM generated tests. Our approach focuses on improving test and variable names produced by search-based tools, while keeping their semantics (i.e., their coverage) unchanged. Our evaluation on nine industrial and open source LLMs show that our readability improvement transformations are overall semantically-preserving and stable across multiple repetitions. Moreover, a human study with ten professional developers, show that our LLM-improved tests are as readable as developer-written tests, regardless of the LLM employed.

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

↑