arXiv(opens in a new tab)cs.SEAug 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2608.24473

Ockhamareto: Pareto-Gated Segment-Level Credit Assignment for Concise Unit-Test Generation with Reinforcement Learning

Dong Huang, Mark Harman, Jie M. Zhang, Zhijiang Guo, Mingzhe Du, See Kiong Ng

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

DONG HUANG, National University of Singapore, Singapore

MARK HARMAN, University College London, London, UK

JIE M. ZHANG, King's College London, London, UK

ZHIJIANG GUO, Hong Kong University of Science and Technology (Guangzhou), Guangzhou, CN

MINGZHE DU ∗^{*}, National University of Singapore, Singapore

SEE-KIONG NG, National University of Singapore, Singapore

We introduce Ockhamareto, a single-shot GRPO framework for unit-test generation and selection, based on the principles of Ockham's Razor and Pareto Optimality. Ockhamareto has two principal components: (i) a Pareto-gated Bonus that rewards only rollouts non-dominated in (mutation, -#tests) space, and (ii) Token-level Segment Credit, which attributes each test's marginal mutation kills back to the tokens of its unit-test block. On the UnLeakedTestBench (ULT), Ockhamareto strictly Pareto-dominates the strongest RL baseline (MIST-RL). Furthermore, it dominates on each and all optimization objectives, catching more bugs (49.9% vs 31.3% mutation score at N=5), using fewer tests (2.60 vs 4.67 on average), thereby achieving 3.4× the per-test trade-off improvement. The advantage is found in all four benchmarks (HumanEval+, MBPP+, CodeContests, TestGenEval-Lite): Ockhamareto leads both mutation and coverage metrics on every one, always with the smallest suite. Ockhamareto also outperforms the state-of-the-art at all model scales, adding +30–35 pp mutation at 4B, 9B, and 27B model sizes. We also show that the knee point of the optimal trade-off between efficiency and effectiveness on the Pareto front is not correlated with obvious more easily computed proxy metrics, such as function size. This finding motivates the Pareto front computation; it is needed to identify this crucial engineering trade-off for each function under test.

CCS Concepts: • Computing methodologies → Natural language generation; • Software and its engineering → Software defect analysis.

Additional Key Words and Phrases: Large language models, unit test generation

1 Introduction

Software testing inevitably faces diminishing returns. Additional tests may reveal additional faults, but they also increase execution, review, and maintenance cost. The practical objective is therefore not simply to generate as many tests as possible, but to obtain test suites that achieve strong fault-detection effectiveness without unnecessary redundancy. This effectiveness–effort trade-off is a longstanding problem in software testing; we revisit its Pareto formulation and the associated question of diminishing returns in §2.1.

∗^{*}Corresponding author.

Authors' Contact Information: Dong HUANG, dhuang@nus.edu.sg, National University of Singapore, Singapore; Mark Harman, mark.harman@ucl.ac.uk, University College London, London, UK; Jie M. Zhang, jie.zhang@kcl.ac.uk, King's College London, London, UK; Zhijiang Guo, zhijiangguo@hkust-gz.edu.cn, Hong Kong University of Science and Technology (Guangzhou), Guangzhou, CN; Mingzhe Du, mingzhe@nus.edu.sg, National University of Singapore, Singapore; See-Kiong Ng, seekiong@nus.edu.sg, National University of Singapore, Singapore.

Figure

This work is licensed under a Creative Commons Attribution 4.0 International License.

© 2026 Copyright held by the owner/author(s).

Dong HUANG, Mark Harman, Jie M. Zhang, Zhijiang Guo, Mingzhe Du, and See-Kiong Ng

The emergence of large language models (LLMs) makes this problem particularly timely. LLMs can generate readable and idiomatic unit tests directly from source code and documentation. Early approaches primarily rely on prompt engineering and iterative refinement. ChatTester first elicits the intention of the focal method and repairs uncompilable tests [34]; SymPrompt issues coverage-guided prompts for different static execution paths [21]; CodaMosa uses LLMs to escape coverage plateaus in search-based test generation [12]; and TestPilot mines usage examples to guide generation and re-generation [22]. These methods substantially improve the ability of LLMs to produce executable and coverage-reaching tests.

Prompt-based generation, however, optimizes test quality only indirectly: the model itself is not trained against the execution outcome that ultimately matters. This limitation has motivated reinforcement learning (RL) from execution feedback, in which generated tests are executed and their observed behavior provides the reward signal. Recent work rewards structural coverage [35], marginal coverage gain [29], or marginal mutation kills [36]. Mutation score is particularly attractive because it measures whether a test suite distinguishes a reference implementation from faulty variants and has been shown to correlate with real-fault detection more strongly than structural coverage alone [9, 11, 19].

Yet an important efficiency problem remains. The strongest recent RL approaches obtain fine-grained per-test feedback through multi-turn generation: the model emits one test, receives execution feedback, and then generates another. This makes per-test credit assignment straightforward, but has two consequences. First, generating an n-test suite requires multiple sequential LLM interactions. Second, the policy is trained to determine whether each newly generated test adds value, rather than whether the suite as a whole provides a good effectiveness-size trade-off. As long as another test produces some marginal gain, generation can continue. The resulting suites can therefore contain many tests whose additional fault-detection value is small relative to their review, execution, and maintenance burden.

A natural alternative is single-shot generation, in which one model call produces the complete test suite. Single-shot generation avoids sequential inference and requires the policy to decide which tests are sufficiently valuable to include in the suite. It also creates a harder learning problem. Standard Group Relative Policy Optimization (GRPO) [24] assigns a scalar advantage to an entire generated trajectory. When that trajectory contains several independently valuable test functions, the policy learns only that “this suite was good”; it cannot tell which individual tests contributed to fault detection and which were redundant.

This exposes two coupled optimization problems at different granularities. At the suite level, the learner must distinguish suites that provide a good effectiveness-size trade-off from suites that achieve similar effectiveness using unnecessary tests. At the test level, it must identify which tests inside a generated suite are responsible for its fault-detection capability. A single scalar trajectory reward provides neither an explicit whole-suite conciseness criterion nor fine-grained attribution among the tests within that trajectory.

We address these problems with Ockhamareto, a single-shot GRPO framework for concise and effective unit-test generation. Ockhamareto combines two complementary mechanisms. First, at the suite level, we introduce a Pareto-gated group-relative bonus. Within each GRPO group, a rollout receives the conciseness bonus only when it is non-dominated with respect to test effectiveness and suite size. A suite that uses more tests without providing greater effectiveness is therefore not rewarded for conciseness, whereas suites representing genuinely different effectiveness-size trade-offs remain eligible. Unlike a fixed penalty on the number of tests, the Pareto gate does not require committing to a universal exchange rate between one additional test and one additional unit of fault detection. Second, at the test level, we introduce token-level segment credit. We attribute each test's marginal mutation kills to the token span corresponding to that test and inject this information as a per-token advantage offset on top of the suite-level GRPO signal. High-yield tests receive positive intra-trajectory credit, whereas redundant or failing tests receive lower or Manuscript submitted to ACM negative credit. Segment credit therefore gives a single-shot policy the fine-grained per-test supervision that multi-turn methods obtain structurally, without requiring one sequential LLM interaction per test. In short, the Pareto gate asks whether the whole suite is worth its size, while segment credit identifies which tests within the suite create its value.

Our empirical results show that these two mechanisms can improve effectiveness and conciseness simultaneously. On UnLeakedTestBench (ULT), Ockhamareto-4B achieves 49.9% mutation score with an average of 2.60 tests at N=5, compared with 31.3% mutation and 4.67 tests for the strongest RL baseline, MIST-RL. Ockhamareto therefore improves mutation by 18.6 percentage points while using 44% fewer tests. Its mutation score largely saturates within the first three tests, and its first test alone achieves 33.3% mutation, already exceeding MIST-RL's 31.3% mutation at five tests. This front-loading behavior is consistent with the intended effect of segment credit: concentrating learning signal on tests that contribute the largest marginal fault-detection value.

The advantage generalizes beyond ULT. Across HumanEval+, MBPP+, CodeContests, and TestGenEval-Lite, Ockhamareto achieves the highest mutation score and statement/branch coverage among the evaluated methods while using the smallest suites. The same reward design also transfers across model scales: at 4B, 9B, and 27B parameters, Ockhamareto improves mutation over the corresponding untuned model by approximately 30–35 percentage points. Notably, Ockhamareto-4B reaches 49.9% mutation compared with 30.5% for the untuned 27B model, showing that model scale alone does not replace the benefit of reward design.

Beyond improving test generation itself, the Pareto formulation also lets us revisit a longstanding engineering question: how many tests are worth maintaining for an individual function? We construct empirical (mutation, #tests) Pareto fronts from generated suites and study their knee points, beyond which additional tests yield diminishing fault-detection returns. On a random 100-function subset of ULT, the median knee occurs at three tests, but individual knees range from one to fourteen tests. Moreover, knee location is not significantly associated with simple static proxies such as lines of code or cyclomatic complexity. This suggests that a fixed rule such as “larger functions require more tests” cannot reliably determine an appropriate suite size; the effectiveness-size trade-off must instead be established empirically for the function under test. Ockhamareto does not itself define a universally optimal stopping point. Rather, it generates substantially stronger low-cost candidate suites and contributes the majority of solutions on the pooled empirical Pareto fronts, making the function-specific trade-off easier to expose and navigate. Our contributions are:

• Joint effectiveness–conciseness formulation. We formulate single-shot unit-test generation as a joint optimization problem over fault-detection effectiveness and suite size, and show empirically that better fault detection need not require larger generated suites. Ockhamareto shifts the observed (mutation, –#tests) frontier outward relative to existing RL baselines.

• Pareto-gated suite-level optimization. We introduce a group-relative Pareto gate that awards a conciseness bonus only to non-dominated rollouts, allowing GRPO to optimize whole-suite effectiveness and size without specifying a fixed scalar exchange rate between the two objectives.

• Token-level segment credit. We introduce fine-grained credit assignment for single-shot test-suite generation by mapping each test’s marginal mutation kills onto its own token span. This provides intra-trajectory per-test supervision while retaining single-shot inference.

• Comprehensive empirical evaluation and Pareto-front analysis. Across five held-out benchmarks and three model scales, we show that Ockhamareto consistently improves fault detection while producing smaller suites. We further characterize per-function empirical Pareto fronts and show that their knee locations vary substantially and are not reliably predicted by simple static code metrics.

Dong HUANG, Mark Harman, Jie M. Zhang, Zhijiang Guo, Mingzhe Du, and See-Kiong Ng