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

基于静态程序分析引导的大语言模型单元测试生成

Static Program Analysis Guided LLM Based Unit Test Generation

Ericsson R&D Bangalore(爱立信班加罗尔研发中心);Ericsson Stockholm(爱立信斯德哥尔摩);Independent Researcher(独立研究者)

Sujoy Roychowdhury, Giriprasad Sridhara, A K Raghavan, Joy Bose, Sourav Mazumdar, Hamender Singh, Srinivasan Bajji Sugumaran, Ricardo Britto

AI总结:

本文提出利用静态程序分析获取简洁精确的上下文信息来增强LLM提示,以解决现有方法依赖示例用法或整个类上下文导致的不可行与扩展性问题,并在商业和开源Java项目上验证了其有效性。

摘要:

我们描述了一种利用大语言模型(LLMs)自动化生成Java方法单元测试的新方法。现有的基于LLM的方法依赖于待测方法(焦点方法)的示例用法,和/或提供焦点方法所在整个类作为输入提示与上下文。前一种方法通常不可行,因为缺少示例用法,尤其是对于新编写的焦点方法。后一种方法的可扩展性不够好;焦点方法复杂度越高、关联类越大,就越难生成充分的测试代码(原因包括超出底层LLM的提示和上下文长度限制等)。我们表明,通过程序分析获得的简洁且精确的上下文信息来增强提示,可以提高通过LLM生成单元测试代码的有效性。我们在一个大型商业Java项目和一个流行的开源Java项目上验证了我们的方法。

英文摘要:

We describe a novel approach to automating unit test generation for Java methods using large language models (LLMs). Existing LLM-based approaches rely on sample usage(s) of the method to test (focal method) and/or provide the entire class of the focal method as input prompt and context. The former approach is often not viable due to the lack of sample usages, especially for newly written focal methods. The latter approach does not scale well enough; the bigger the complexity of the focal method and larger associated class, the harder it is to produce adequate test code (due to factors such as exceeding the prompt and context lengths of the underlying LLM). We show that augmenting prompts with \emph{concise} and \emph{precise} context information obtained by program analysis %of the focal method increases the effectiveness of generating unit test code through LLMs. We validate our approach on a large commercial Java project and a popular open-source Java project.

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

↑