用强化学习生成更少但更有效的测试,提升代码验证效率
MIST-RL: Mutation-based Incremental Suite Testing via Reinforcement Learning
- 用强化学习优化测试生成,动态奖励新故障发现、惩罚重复断言
- 测试量减少19.3%但突变检测率提升28.5%,验证准确率提高3.05%
- 适合需要高效代码验证的开发者和自动化测试场景
大型语言模型在首次生成正确代码时常失败,需依赖生成的单元测试进行验证。尽管近期验证方法取得进展,但仍受限于“按数量扩展”的范式,该方法导致故障检测收益递减且测试冗余严重。为此,我们提出 MIST-RL(基于突变的增量测试套件生成强化学习框架),将重点转向“按效用扩展”。我们将测试生成建模为序列决策过程,采用组相对策略优化(GRPO)进行优化。具体引入一种新的增量突变奖励机制,并结合动态惩罚,激励模型发现新故障,同时抑制功能等价的断言。在 HumanEval+ 与 MBPP+ 数据集上的实验表明,MIST-RL 显著优于现有基线:突变得分提升 28.5%,测试用例数量减少 19.3%。此外,这些紧凑高效的测试作为验证器,使 HumanEval+ 上的代码重排序准确率相比 SOTA 基线提升 3.05%(使用 10 个候选样本)。源代码与数据见附录。
原文摘要 · Abstract (English)
Large Language Models (LLMs) often fail to generate correct code on the first attempt, which requires using generated unit tests as verifiers to validate the solutions. Despite the success of recent verification methods, they remain constrained by a "scaling-by-quantity" paradigm. This brute-force approach suffers from a critical limitation: it yields diminishing returns in fault detection while causing severe test redundancy. To address this, we propose MIST-RL (Mutation-based Incremental Suite Testing via Reinforcement Learning), a framework that shifts the focus to "scaling-by-utility". We formulate test generation as a sequential decision process optimized via Group Relative Policy Optimization (GRPO). Specifically, we introduce a novel incremental mutation reward combined with dynamic penalties, which incentivizes the model to discover new faults while it suppresses functionally equivalent assertions. Experiments on HumanEval+ and MBPP+ demonstrate that MIST-RL outperforms state-of-the-art baselines. It achieves a +28.5% higher mutation score while reducing the number of test cases by 19.3%. Furthermore, we show that these compact, high-utility tests serve as superior verifiers, which improves downstream code reranking accuracy on HumanEval+ by 3.05% over the SOTA baseline with 10 candidate samples. The source code and data are provided in the supplementary material.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。