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

Benjamin Steenhoek, Michele Tufano, Neel Sundaresan, Alexey Svyatkovskiy
10/3/2023
cs.SEcs.LG

No confident code implementation found for this paper. 1 possible match can be shown below.

Abstract

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.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. 1 weaker match is hidden by default — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Cite this paper

@article{steenhoek2023reinforcement,
  title  = {Reinforcement Learning from Automatic Feedback for High-Quality Unit Test Generation},
  author = {Benjamin Steenhoek and Michele Tufano and Neel Sundaresan and Alexey Svyatkovskiy},
  year   = {2023},
  eprint = {2310.02368},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2310.02368v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2310.02368.svg)](https://codeofpaper.com/paper/2310.02368)

Discussion