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

基于自动反馈的强化学习用于高质量单元测试生成

Reinforcement Learning from Automatic Feedback for High-Quality Unit Test Generation

Microsoft(微软);Google(谷歌);Google DeepMind(谷歌DeepMind)

Benjamin Steenhoek, Michele Tufano, Neel Sundaresan, Alexey Svyatkovskiy

AI总结:

针对 LLM 生成单元测试含测试坏味道的问题,提出 RLSQM,用静态质量指标构建奖励并通过 PPO 强化优化,显著提升测试质量且多项指标超过 GPT-4。

摘要:

软件测试是软件开发的一个关键方面,而创建遵循最佳实践的高质量测试对于有效维护至关重要。近年来,大型语言模型(LLM)在代码生成(包括测试用例的自动创建)方面受到欢迎。然而,这些 LLM 通常基于大量公开可用的代码进行训练,其中可能包含不遵循最佳实践的测试用例,甚至可能含有测试坏味道(反模式)。为解决这一问题,我们提出了一种称为“基于静态质量指标的强化学习”(RLSQM)的新技术。首先,我们分析 LLM 生成的反模式,并证明 LLM 可能生成不理想的测试坏味道。因此,我们为每个静态质量指标训练特定的奖励模型,然后使用近端策略优化(PPO)训练模型,使其每次优化一个质量指标。此外,我们将这些奖励合并为一个统一的奖励模型,旨在捕捉测试的不同最佳实践和质量方面。通过将强化学习训练的模型与使用监督学习训练的模型进行比较,我们深入探讨了如何可靠地利用强化学习提高测试生成质量,以及各种训练策略的效果。实验结果表明,与基础 LLM 相比,经强化学习优化的模型持续生成高质量测试用例,模型性能最高提升 21%,并成功生成接近 100% 语法正确的代码。RLSQM 还在七项指标中的四项上优于 GPT-4。这代表着通过强化学习和静态质量指标提升软件测试整体效率与可靠性迈出的重要一步。我们的数据可在 https://figshare.com/s/ded476c8d4c221222849 获取。

英文摘要:

Software testing is a crucial aspect of software development, and the creation of high-quality tests that adhere to best practices is essential for effective maintenance. Recently, Large Language Models (LLMs) have gained popularity for code generation, including the automated creation of test cases. However, these LLMs are often trained on vast amounts of publicly available code, which may include test cases that do not adhere to best practices and may even contain test smells (anti-patterns). To address this issue, we propose a novel technique called Reinforcement Learning from Static Quality Metrics (RLSQM). To begin, we analyze the anti-patterns generated by the LLM and show that LLMs can generate undesirable test smells. Thus, we train specific reward models for each static quality metric, then utilize Proximal Policy Optimization (PPO) to train models for optimizing a single quality metric at a time. Furthermore, we amalgamate these rewards into a unified reward model aimed at capturing different best practices and quality aspects of tests. By comparing RL-trained models with those trained using supervised learning, we provide insights into how reliably utilize RL to improve test generation quality and into the effects of various training strategies. Our experimental results demonstrate that the RL-optimized model consistently generated high-quality test cases compared to the base LLM, improving the model by up to 21%, and successfully generates nearly 100% syntactically correct code. RLSQM also outperformed GPT-4 on four out of seven metrics. This represents a significant step towards enhancing the overall efficiency and reliability of software testing through Reinforcement Learning and static quality metrics. Our data are available at https://figshare.com/s/ded476c8d4c221222849.

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

↑