arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2408.11710cs.SEcs.AI
收藏

利用大语言模型提升生成单元测试的可理解性

Leveraging Large Language Models for Enhancing the Understandability of Generated Unit Tests

Delft University of Technology(代尔夫特理工大学)

Amirhossein Deljouyi, Roham Koohestani, Maliheh Izadi, Andy Zaidman

AI总结:

本文提出 UTGen,结合基于搜索的软件测试和大语言模型,通过情境化测试数据、改进标识符命名和添加注释来提升自动生成单元测试的可理解性。实验表明,使用 UTGen 测试用例的参与者修复 bug 数量增加 33%,耗时减少 20%。

摘要:

自动化单元测试生成器,特别是像 EvoSuite 这样的基于搜索的软件测试工具,能够生成具有高覆盖率的测试。尽管这些生成器减轻了编写单元测试的负担,但它们常常给软件工程师在理解生成的测试方面带来挑战。为了解决这个问题,我们引入了 UTGen,它结合了基于搜索的软件测试和大语言模型,以增强自动生成测试用例的可理解性。我们通过将测试数据情境化、改进标识符命名以及添加描述性注释来实现这一提升。通过一项由来自学术界和工业界的 32 名参与者参与的控制实验,我们调查了单元测试的可理解性如何影响软件工程师执行错误修复任务的能力。我们选择错误修复来模拟一个强调可理解测试用例重要性的真实世界场景。我们观察到,与基线测试用例相比,使用 UTGen 测试用例进行任务的参与者修复的 bug 多达 33%,使用的时间减少了多达 20%。从测试后问卷中,我们收集到参与者认为增强的测试名称、测试数据和变量名改善了他们的错误修复过程。

英文摘要:

Automated unit test generators, particularly search-based software testing tools like EvoSuite, are capable of generating tests with high coverage. Although these generators alleviate the burden of writing unit tests, they often pose challenges for software engineers in terms of understanding the generated tests. To address this, we introduce UTGen, which combines search-based software testing and large language models to enhance the understandability of automatically generated test cases. We achieve this enhancement through contextualizing test data, improving identifier naming, and adding descriptive comments. Through a controlled experiment with 32 participants from both academia and industry, we investigate how the understandability of unit tests affects a software engineer's ability to perform bug-fixing tasks. We selected bug-fixing to simulate a real-world scenario that emphasizes the importance of understandable test cases. We observe that participants working on assignments with UTGen test cases fix up to 33% more bugs and use up to 20% less time when compared to baseline test cases. From the post-test questionnaire, we gathered that participants found that enhanced test names, test data, and variable names improved their bug-fixing process.

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

↑