An empirical study of LoRA-based fine-tuning of large language models for automated test case generation

📄 arXiv: 2604.06946v1 📥 PDF

作者: Milad Moradi, Ke Yan, David Colwell, Rhona Asgari

分类: cs.SE, cs.AI

发布日期: 2026-04-08


💡 一句话要点

LoRA微调提升大语言模型在自动化测试用例生成中的性能

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 自动化测试用例生成 大语言模型 LoRA微调 参数高效微调 GPT-4o评估 软件测试 开源模型 模型微调

📋 核心要点

  1. 现有方法难以有效处理需求歧义,并生成结构化的可执行测试用例,自动化测试用例生成面临挑战。
  2. 论文采用LoRA进行参数高效微调,针对性地提升大语言模型在测试用例生成任务上的表现。
  3. 实验表明,LoRA微调显著提升开源模型性能,微调后的开源模型性能可媲美甚至超越部分预训练的专有模型。

📝 摘要(中文)

本文针对基于自然语言需求自动生成测试用例这一软件工程难题,提出了一种基于LoRA的参数高效微调方法,并对多种大语言模型进行了全面的实证研究。该研究在一个统一的实验流程下,评估了包括开源和专有模型在内的多个LLM家族,并系统地探索了LoRA的关键超参数(如秩、缩放因子和dropout)对下游性能的影响。论文提出了一种基于GPT-4o的自动化评估框架,该框架从九个质量维度评估生成的测试用例。实验结果表明,基于LoRA的微调显著提高了所有开源模型的性能,其中Ministral-8B表现最佳。此外,微调后的8B开源模型可以达到与预微调的GPT-4.1模型相当的性能,突出了参数高效适应的有效性。虽然GPT-4.1模型实现了最高的整体性能,但微调后专有模型和开源模型之间的性能差距显著缩小。这些发现为自动化测试生成的模型选择、微调策略和评估方法提供了重要的见解。特别是,它们表明,当与精心设计的微调方法相结合时,具有成本效益且可本地部署的开源模型可以作为专有系统的可行替代方案。

🔬 方法详解

问题定义:论文旨在解决从自然语言需求自动生成高质量测试用例的问题。现有方法在处理需求中的歧义性以及生成结构化、可执行的测试工件方面存在不足,导致自动化测试用例生成的质量和效率不高。

核心思路:论文的核心思路是利用LoRA(Low-Rank Adaptation)进行参数高效的微调,从而使大型语言模型能够更好地适应测试用例生成任务。LoRA通过引入低秩矩阵来近似模型参数的更新,从而减少需要训练的参数数量,降低计算成本和存储需求。

技术框架:整体框架包括以下几个主要步骤:1) 选择预训练的大语言模型(包括开源和专有模型);2) 使用LoRA方法对选定的模型进行微调,针对测试用例生成任务进行优化;3) 使用提出的基于GPT-4o的自动化评估框架,从多个维度评估生成的测试用例的质量;4) 分析实验结果,比较不同模型和不同LoRA超参数设置下的性能表现。

关键创新:论文的关键创新在于:1) 系统地研究了LoRA在自动化测试用例生成中的应用,并评估了不同LoRA超参数的影响;2) 提出了一个基于GPT-4o的自动化评估框架,能够从多个维度评估生成的测试用例的质量,避免了人工评估的主观性;3) 证明了通过LoRA微调,开源模型可以达到与专有模型相当的性能,为使用低成本的开源方案提供了可能性。

关键设计:论文实验中,关键设计包括:1) 选择了多个具有代表性的大语言模型,包括开源的Ministral-8B和专有的GPT-4.1;2) 系统地探索了LoRA的超参数,如秩(rank)、缩放因子(scaling factor)和dropout,并分析了它们对性能的影响;3) 使用GPT-4o作为评估器,从九个质量维度(如正确性、完整性和可执行性)评估生成的测试用例。

📊 实验亮点

实验结果表明,基于LoRA的微调显著提高了开源模型的性能,其中Ministral-8B表现最佳。微调后的8B开源模型可以达到与预微调的GPT-4.1模型相当的性能。虽然GPT-4.1模型实现了最高的整体性能,但微调后专有模型和开源模型之间的性能差距显著缩小。

🎯 应用场景

该研究成果可应用于软件测试自动化领域,帮助开发人员更高效地生成高质量的测试用例,从而提高软件质量、降低开发成本。通过LoRA微调,企业可以使用成本更低的开源模型替代昂贵的专有模型,实现测试流程的自动化,加速软件交付。

📄 摘要(原文)

Automated test case generation from natural language requirements remains a challenging problem in software engineering due to the ambiguity of requirements and the need to produce structured, executable test artifacts. Recent advances in LLMs have shown promise in addressing this task; however, their effectiveness depends on task-specific adaptation and efficient fine-tuning strategies. In this paper, we present a comprehensive empirical study on the use of parameter-efficient fine-tuning, specifically LoRA, for requirement-based test case generation. We evaluate multiple LLM families, including open-source and proprietary models, under a unified experimental pipeline. The study systematically explores the impact of key LoRA hyperparameters, including rank, scaling factor, and dropout, on downstream performance. We propose an automated evaluation framework based on GPT-4o, which assesses generated test cases across nine quality dimensions. Experimental results demonstrate that LoRA-based fine-tuning significantly improves the performance of all open-source models, with Ministral-8B achieving the best results among them. Furthermore, we show that a fine-tuned 8B open-source model can achieve performance comparable to pre-fine-tuned GPT-4.1 models, highlighting the effectiveness of parameter-efficient adaptation. While GPT-4.1 models achieve the highest overall performance, the performance gap between proprietary and open-source models is substantially reduced after fine-tuning. These findings provide important insights into model selection, fine-tuning strategies, and evaluation methods for automated test generation. In particular, they demonstrate that cost-efficient, locally deployable open-source models can serve as viable alternatives to proprietary systems when combined with well-designed fine-tuning approaches.