CITYWALK:通过项目依赖感知与特定语言知识增强基于LLM的C++单元测试生成
CITYWALK: Enhancing LLM-Based C++ Unit Test Generation via Project-Dependency Awareness and Language-Specific Knowledge
AI总结:
本文提出CITYWALK框架,通过程序分析感知项目依赖并结合C++特定语言知识,利用GPT-4o生成高覆盖率单元测试,在十个C++项目上优于现有方法。
摘要:
单元测试在软件开发生命周期中起着关键作用,因为它能确保代码质量。然而,在实践中编写高质量的单元测试对开发者来说仍然是一项耗时的任务。最近,大语言模型(LLMs)在自动化单元测试生成中的应用展现出了可喜的成果。现有方法主要关注解释型编程语言(如Java),而针对C++等编译型编程语言的成熟解决方案仍有待探索。C++复杂的语言特性(如指针、模板和虚函数)给LLM生成既可执行又具有高覆盖率的单元测试带来了特殊挑战。为了解决上述问题,本文提出了CITYWALK,一个基于LLM的C++单元测试生成新框架。CITYWALK通过程序分析提供对被测项目内部依赖关系的全面理解来增强LLM。此外,CITYWALK结合了从项目文档和经验观察中提取的C++特定语言知识,显著提高了LLM生成单元测试的正确性。我们采用广泛流行的大语言模型GPT-4o实现了CITYWALK。实验结果表明,CITYWALK在十个流行的C++项目集合上优于当前最先进的方法。我们的发现证明了CITYWALK在生成高质量C++单元测试方面的有效性。
英文摘要:
Unit testing plays a pivotal role in the software development lifecycle, as it ensures code quality. However, writing high-quality unit tests remains a time-consuming task for developers in practice. More recently, the application of large language models (LLMs) in automated unit test generation has demonstrated promising results. Existing approaches primarily focus on interpreted programming languages (e.g., Java), while mature solutions tailored to compiled programming languages like C++ are yet to be explored. The intricate language features of C++, such as pointers, templates, and virtual functions, pose particular challenges for LLMs in generating both executable and high-coverage unit tests. To tackle the aforementioned problems, this paper introduces CITYWALK, a novel LLM-based framework for C++ unit test generation. CITYWALK enhances LLMs by providing a comprehensive understanding of the dependency relationships within the project under test via program analysis. Furthermore, CITYWALK incorporates language-specific knowledge about C++ derived from project documentation and empirical observations, significantly improving the correctness of the LLM-generated unit tests. We implement CITYWALK by employing the widely popular LLM GPT-4o. The experimental results show that CITYWALK outperforms current state-of-the-art approaches on a collection of ten popular C++ projects. Our findings demonstrate the effectiveness of CITYWALK in generating high-quality C++ unit tests.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。