NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Klear-CodeTest: Scalable Test Case Generation for Code Reinforcement Learning

Jia Fu, Xinyu Yang, Hongzhi Zhang, Yahui Liu, Jingyuan Zhang, Qi Wang, Fuzheng Zhang, Guorui ZhouarXiv 2025 · DOI

Abstract

Reinforcement Learning (RL) for code is often hindered by the difficulty of obtaining high-quality rewards at scale. Klear-CodeTest introduces a scalable framework for generating massive, high-quality test case suites using a novel Generator-Validation (G-V) approach. By cross-referencing multiple "gold" solutions within a high-performance secure sandbox, the researchers produced a dataset of nearly 28,000 problems. This dataset significantly improves the performance and training stability of Large Language Models (LLMs) on complex programming tasks, particularly in medium and hard difficulty categories.

Introduction

Reinforcement Learning (RL) has become a cornerstone for improving Large Language Models (LLMs). However, applying RL to code generation is notoriously difficult due to the "reward problem." To train a model via RL, a reliable reward signal is needed to determine if the generated code is correct, typically derived from unit tests.

High-quality unit tests are difficult to find at scale. The authors identify three primary challenges in automated testing for code:

  1. Ambiguity: Natural language requirements often leave edge cases undefined.
  2. The Oracle Problem: Determining the correct output for an arbitrary input without a reference implementation is non-trivial.
  3. Test Case Coverage: Generating tests that catch subtle bugs, such as off-by-one errors or inefficient algorithms, is resource-intensive.

The Klear-CodeTest Framework

The authors introduce the Klear-CodeTest framework, which employs a "Generator-Validation" (G-V) pipeline to automate the creation of robust test suites.

The Klear-CodeTest framework pipeline, illustrating the Generator-Validation (G-V) approach from prompt to validated input-output pairs.

Key Components:

  • Code-Based Generation: Instead of direct test case generation, the LLM is prompted to write a generator program. This program produces 80 regular test cases and 20 corner cases.
  • Consistency Validation: To address the Oracle Problem, generated inputs are executed against two independent "gold" (human-written) solutions. A test case is only deemed valid if both solutions produce identical outputs, filtering out ambiguous requirements.
  • Iterative Repair: If a generator program fails, error logs are fed back to the LLM for repair. Approximately 80% of problems are successfully covered within two iterations.
  • The "Judge" Sandbox: A custom sandbox using ptrace for system call filtering ensures secure and efficient execution of untrusted code, reducing inference time by up to 44.6%.

Data Curation and Scale

The researchers curated a massive dataset by aggregating and enhancing public sources such as Codeforces, TACO-verified, and CodeContests.

Comparison of Klear-CodeTest with existing code datasets and benchmarks, highlighting its superior scale and test density.

The resulting Klear-CodeTest (New) dataset contains 27,965 problems with an average of 86 test cases per problem, significantly exceeding the density of previous training sets.

Results and Impact

Klear-CodeTest demonstrates significant improvements in both test quality and model performance:

  • High Quality: Generated test cases achieved a True Positive Rate (TPR) of 91.4% and a True Negative Rate (TNR) of 87.8%, outperforming official test cases in the CodeContests dataset.
  • RL Performance Boost: Training a Qwen3-4B model using Direct Alignment Policy Optimization (DAPO) with Klear-CodeTest data led to substantial accuracy gains on LiveCodeBench.
  • Hard Problem Mastery: The most significant gains occurred in "Medium" and "Hard" problems. On Hard problems, accuracy increased from 21.5% to 27.5%.
  • Stability: High-quality rewards led to more stable training curves, preventing the "entropy collapse" common in RL models trained on noisy data.

Conclusion

Klear-CodeTest provides a scalable solution to the reward problem in code RL. By leveraging gold solutions as oracles and focusing on corner cases, the framework enables the creation of high-fidelity training signals. Future work will focus on deeper integration of the "Judge" sandbox into RL frameworks and expanding into full-stack and systems-level code testing.

The framework, dataset, and sandbox are open-sourced at https://github.com/Kwai-Klear/CodeTest.

Summary updated

BibTeX
@misc{fu2025klear,
  author = {Jia Fu and Xinyu Yang and Hongzhi Zhang and Yahui Liu and Jingyuan Zhang and Qi Wang and Fuzheng Zhang and Guorui Zhou},
  title = {{Klear-CodeTest: Scalable Test Case Generation for Code Reinforcement Learning}},
  year = {2025},
  eprint = {2508.05710},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.05710},
}
Figure