Table of Contents
Fetching ...

Scaling Test-Driven Code Generation from Functions to Classes: An Empirical Study

Yunhao Liang, Ruixuan Ying, Shiwen Ni, Zhe Cui

TL;DR

This work extends test-driven code generation from function-level tasks to class-level synthesis by introducing a dependency-aware class-level TDD framework. It decomposes class construction into method-level TDD loops guided by intra-class dependency analysis, and uses reflective repair with bounded budget to fix failures. A cleaned benchmark, ClassEval-TDD, provides deterministic specifications, aligned skeletons, and complete method-level tests to enable reliable evaluation. Across eight diverse LLMs, the approach yields substantial gains over strong baselines, achieving up to 71% fully correct classes, with low repair overhead, and reveals remaining challenges around intra-class dependencies and schedule correctness. The findings advocate for reliable benchmarks and nucleus techniques (dependency-aware scheduling, executable method tests, and localized repair) to scale class-level code generation in practice.

Abstract

Test-driven development (TDD) has been adopted to improve Large Language Model (LLM)-based code generation by using tests as executable specifications. However, existing TDD-style code generation studies are largely limited to function-level tasks, leaving class-level synthesis where multiple methods interact through shared state and call dependencies underexplored. In this paper, we scale test-driven code generation from functions to classes via an iterative TDD framework. Our approach first analyzes intra-class method dependencies to derive a feasible generation schedule, and then incrementally implements each method under method-level public tests with reflection-style execution feedback and bounded repair iterations. To support test-driven generation and rigorous class-level evaluation, we construct ClassEval-TDD, a cleaned and standardized variant of ClassEval with consistent specifications, deterministic test environments, and complete method-level public tests. We conduct an empirical study across eight LLMs and compare against the strongest direct-generation baseline (the best of holistic, incremental, and compositional strategies). Our class-level TDD framework consistently improves class-level correctness by 12 to 26 absolute points and achieves up to 71% fully correct classes, while requiring only a small number of repairs on average. These results demonstrate that test-driven generation can effectively scale beyond isolated functions and substantially improve class-level code generation reliability. All code and data are available at https://anonymous.4open.science/r/ClassEval-TDD-C4C9/

Scaling Test-Driven Code Generation from Functions to Classes: An Empirical Study

TL;DR

This work extends test-driven code generation from function-level tasks to class-level synthesis by introducing a dependency-aware class-level TDD framework. It decomposes class construction into method-level TDD loops guided by intra-class dependency analysis, and uses reflective repair with bounded budget to fix failures. A cleaned benchmark, ClassEval-TDD, provides deterministic specifications, aligned skeletons, and complete method-level tests to enable reliable evaluation. Across eight diverse LLMs, the approach yields substantial gains over strong baselines, achieving up to 71% fully correct classes, with low repair overhead, and reveals remaining challenges around intra-class dependencies and schedule correctness. The findings advocate for reliable benchmarks and nucleus techniques (dependency-aware scheduling, executable method tests, and localized repair) to scale class-level code generation in practice.

Abstract

Test-driven development (TDD) has been adopted to improve Large Language Model (LLM)-based code generation by using tests as executable specifications. However, existing TDD-style code generation studies are largely limited to function-level tasks, leaving class-level synthesis where multiple methods interact through shared state and call dependencies underexplored. In this paper, we scale test-driven code generation from functions to classes via an iterative TDD framework. Our approach first analyzes intra-class method dependencies to derive a feasible generation schedule, and then incrementally implements each method under method-level public tests with reflection-style execution feedback and bounded repair iterations. To support test-driven generation and rigorous class-level evaluation, we construct ClassEval-TDD, a cleaned and standardized variant of ClassEval with consistent specifications, deterministic test environments, and complete method-level public tests. We conduct an empirical study across eight LLMs and compare against the strongest direct-generation baseline (the best of holistic, incremental, and compositional strategies). Our class-level TDD framework consistently improves class-level correctness by 12 to 26 absolute points and achieves up to 71% fully correct classes, while requiring only a small number of repairs on average. These results demonstrate that test-driven generation can effectively scale beyond isolated functions and substantially improve class-level code generation reliability. All code and data are available at https://anonymous.4open.science/r/ClassEval-TDD-C4C9/
Paper Structure (74 sections, 2 figures, 9 tables)