Learning to Generate Unit Test via Adversarial Reinforcement Learning
Dongjun Lee, Changho Hwang, Kimin Lee
摘要
Unit testing is a core practice in programming, enabling systematic evaluation of programs produced by human developers or large language models (LLMs). Given the challenges in writing comprehensive unit tests, LLMs have been employed to automate unit test generation, yet methods for training LLMs to produce high-quality unit tests remain underexplored. In this work, we propose UTRL, a novel reinforcement learning (RL) framework that trains an LLM to generate high-quality unit test given a programming instruction. Our key idea is to iteratively train two LLMs, the unit test generator and the code generator, in an adversarial manner via RL: (1) the unit test generator is trained to maximize a discrimination reward, encouraging it to produce tests that reveal faults in the code generator's solutions; and (2) the code generator is trained to maximize a code reward, encouraging it to produce solutions that pass the unit tests generated by the unit test generator. In our experiment, we demonstrate that unit tests generated by Qwen3-4B trained via UTRL show higher quality compared to unit tests generated by the same model trained via supervised fine-tuning on ground-truth unit tests, yielding code evaluations that more closely align with those induced by the ground-truth tests. Moreover, Qwen3-4B trained with UTRL outperforms frontier models like GPT-4.1 and GPT-4o in generating high-quality unit tests, highlighting the effectiveness of UTRL in training LLMs for the unit test generation. Code and relevant materials are available at our project page: https://dgjun32.github.io/UTRL .
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 2 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- Model Alignment as Prospect Theoretic Optimization 引用了 Direct Preference Optimization: Your Language Model is Secretly a Reward Model
- Model Alignment as Prospect Theoretic Optimization 引用了 Training language models to follow instructions with human feedback
- DAPO: An Open-Source LLM Reinforcement Learning System at Scale 引用了 CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning
- DAPO: An Open-Source LLM Reinforcement Learning System at Scale 引用了 Training language models to follow instructions with human feedback
- CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning 引用了 Training language models to follow instructions with human feedback
- Direct Preference Optimization: Your Language Model is Secretly a Reward Model 引用了 Training language models to follow instructions with human feedback
- V1: Unifying Generation and Self-Verification for Parallel Reasoners 引用了 DAPO: An Open-Source LLM Reinforcement Learning System at Scale
引用它的顶会 Paper2
- V1: Unifying Generation and Self-Verification for Parallel ReasonersHarman Singh, Xiuyu Li, Kusha Sareen, Monishwaran Maheswaran 等ICML 2026 · 8 次引用
- CodeChemist: Test-Time Scaling for Low-Resource Code Generation via Functional Knowledge TransferKaiXin Wang, Tianlin Li, Xiaoyu Zhang, Aishan Liu 等ICML 2026
它引用的 Paper15
- Training language models to follow instructions with human feedbackLong Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida 等NeurIPS 2022 · 24,707 次引用
- Direct Preference Optimization: Your Language Model is Secretly a Reward ModelRafael Rafailov, Archit Sharma, Eric Mitchell, Christopher D. Manning 等NeurIPS 2023 · 10,924 次引用
- DAPO: An Open-Source LLM Reinforcement Learning System at ScaleQiying Yu, Zheng Zhang, Ruofei Zhu, Yufeng Yuan 等NeurIPS 2025 · 2,828 次引用
- Model Alignment as Prospect Theoretic OptimizationKawin Ethayarajh, Winnie Xu, Niklas Muennighoff, Dan Jurafsky 等ICML 2024 · 973 次引用
- CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement LearningHung Le, Yue Wang, Akhilesh Deepak Gotmare, Silvio Savarese 等NeurIPS 2022 · 571 次引用
相关 Paper
- ATGen: Adversarial Reinforcement Learning for Test Case GenerationQingyao Li, Xinyi Dai, Weiwen Liu, Xiangyang Li 等ICLR 2026 · 4 次引用
- Co-Evolving LLM Coder and Unit Tester via Reinforcement LearningYinjie Wang, Ling Yang, Ye Tian, Ke Shen 等NeurIPS 2025 · 56 次引用
- Evaluating and Improving ChatGPT for Unit Test GenerationZhiqiang Yuan, Mingwei Liu, Shiji Ding, Kaixin Wang 等FSE 2024 · 89 次引用
- Dynamic Scaling of Unit Tests for Code Reward ModelingZeyao Ma, Xiaokang Zhang, Jing Zhang, Jifan Yu 等ACL 2025 · 21 次引用
- CodeRM-NT: Reward Model for Code RL without Unit TestsXiao Xia, Dan Zhang, Tianrui SunACL Findings 2026
