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

HarnessLLM: Automatic Testing Harness Generation via Reinforcement Learning

Yujian Liu, Jiabao Ji, Yang Zhang, Wenbo Guo, Tommi S. Jaakkola, Shiyu Chang · DOI

Introduction

Current Large Language Model (LLM) code testing methodologies primarily rely on generating static input-output (I/O) pairs. However, this approach faces a fundamental limitation: the LLM acting as the tester is often less capable of complex logic than the program it is tasked with verifying. Consequently, LLM-generated test suites frequently consist of simple, homogeneous cases that fail to identify deep logical bugs or edge cases.

HarnessLLM proposes a paradigm shift from predicting exact outputs to writing executable test harnesses. These harnesses are Python scripts that programmatically generate diverse inputs and validate outputs through invariants or reference comparisons.

Comparison of traditional input-output testing versus the proposed programmatic test harness approach.

Methodology

The HarnessLLM framework utilizes a two-stage training pipeline to instill the ability to write robust testing code:

  1. Supervised Fine-Tuning (SFT) Warm-up: A large teacher model (Qwen3-32B) generates initial harnesses. These are filtered to ensure they correctly identify bugs in known faulty code while passing on ground-truth programs. This high-quality data is used to fine-tune smaller models like Qwen3-4B.
  2. Reinforcement Learning with Verifiable Rewards (RLVR): The models are further optimized using the Group Relative Policy Optimization (GRPO) algorithm. The reward function is specifically designed to encourage bug detection: a model receives a positive reward (+1) only if its generated harness passes the ground-truth program but fails the buggy program. This prevents the model from "gaming" the system by writing tests that fail indiscriminately.

Key Results and Insights

The transition to programmatic testing significantly enhances the model's debugging capabilities. While massive models like Qwen3-32B initially struggle with harness generation out-of-the-box, RL training unlocks this latent reasoning skill.

Bug finding performance (True Bug Rate %) on LiveCodeBench and Codeforces, comparing I/O testing and HarnessLLM across different model scales.

As shown in the results, the RL-trained Qwen3-4B model achieved a True Bug Rate (TBR) of 69.9% on LiveCodeBench and 74.4% on Codeforces. This performance exceeds both the traditional I/O-based baselines and the much larger 32B teacher model. Furthermore, the harness approach demonstrated superior generalization, showing a 17% relative improvement over I/O testing when evaluating bugs generated by unseen models.

Beyond bug finding, HarnessLLM also improves code generation. By using the generated harnesses to select the best candidate from multiple model outputs, the pass@1 rate for Qwen3-32B on LiveCodeBench increased from 63.5% to 69.5%.

Conclusion

HarnessLLM demonstrates that training models to write code that tests code is a more scalable and effective strategy than simple output prediction. By leveraging reinforcement learning with verifiable rewards, smaller models can be trained to outperform much larger counterparts in identifying complex software defects. Future work will focus on reducing the dependency on ground-truth programs and extending the framework to security vulnerability detection.

Summary updated

BibTeX
@inproceedings{liu2025harnessllm,
  author = {Yujian Liu and Jiabao Ji and Yang Zhang and Wenbo Guo and Tommi S. Jaakkola and Shiyu Chang},
  title = {{HarnessLLM: Automatic Testing Harness Generation via Reinforcement Learning}},
  booktitle = {DL4C @ NeurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=GLPMu8aHzk},
}
Figure