用语言服务器实时获取代码上下文,实现跨语言即时生成高覆盖测试用例。
LSPRAG: LSP-Guided RAG for Language-Agnostic Real-Time Unit Test Generation
- 利用语言服务器协议(LSP)实时获取函数定义与引用,精准构建提示上下文。
- 在Java、Go、Python项目上,测试覆盖率最高提升213.31%,显著优于基线方法。
- 无需为每种语言单独设计分析工具,适合快速集成到多语言开发流程中。
自动化单元测试生成对软件质量至关重要,但现有方法难以跨编程语言泛化且无法满足实时开发需求。尽管大语言模型(LLMs)展现出潜力,其生成高覆盖率测试代码的能力仍受限于提示上下文的简洁性。当前基于检索增强生成的方法或依赖不精确的相似性搜索,或需构建昂贵的、语言专用的静态分析流水线。为此,我们提出LSPRAG框架,通过复用现成的语言服务器协议(LSP)后端,为LLM提供实时、语言感知的精准符号定义与引用信息,实现低维护成本的上下文检索。我们在涵盖Java、Go和Python的开源项目上进行了评估。相比最佳基线方法,LSPRAG在Golang上提升线覆盖率达174.55%,Java达213.31%,Python达31.57%。
原文摘要 · Abstract (English)
Automated unit test generation is essential for robust software development, yet existing approaches struggle to generalize across multiple programming languages and operate within real-time development. While Large Language Models (LLMs) offer a promising solution, their ability to generate high coverage test code depends on prompting a concise context of the focal method. Current solutions, such as Retrieval-Augmented Generation, either rely on imprecise similarity-based searches or demand the creation of costly, language-specific static analysis pipelines. To address this gap, we present LSPRAG, a framework for concise-context retrieval tailored for real-time, language-agnostic unit test generation. LSPRAG leverages off-the-shelf Language Server Protocol (LSP) back-ends to supply LLMs with precise symbol definitions and references in real time. By reusing mature LSP servers, LSPRAG provides an LLM with language-aware context retrieval, requiring minimal per-language engineering effort. We evaluated LSPRAG on open-source projects spanning Java, Go, and Python. Compared to the best performance of baselines, LSPRAG increased line coverage by up to 174.55% for Golang, 213.31% for Java, and 31.57% for Python.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。