一句话:提出 LSPRAG,利用 LSP 实时检索精确上下文,实现语言无关的单元测试生成并提升覆盖率。
自动单元测试生成对软件质量保障很重要,但现有方法难以跨语言泛化并支持实时开发。LLM 可生成测试,却依赖焦点方法的简洁上下文;现有 RAG 要么使用不精确的相似度检索,要么需要昂贵的语言专用静态分析。本文提出 LspRag,一个面向实时、语言无关单元测试生成的简洁上下文检索框架。它复用现成 Language Server Protocol 后端,为 LLM 实时提供精确的符号定义与引用,从而实现语言感知的上下文检索,且每语言工程开销很小。作者在 Java、Go、Python 开源项目上评估。与最佳基线相比,LspRag 将行覆盖率最高提升 174.55%(Go)、213.31%(Java)和 31.57%(Python)。
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.
@inproceedings{abs-2510-22210,
title = {LSPRAG: LSP-Guided RAG for Language-Agnostic Real-Time Unit Test Generation},
author = {Gwihwan Go and Quan Zhang and Chijin Zhou and Zhao Wei and Yu Jiang},
booktitle = {ICSE},
year = {2026},
doi = {10.1145/3744916.3773189}
}