AI-Assisted Unit Test Writing and Test-Driven Code Refactoring: A Case Study

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Smolic, Ema, Brcic, Mario, Hobor, Luka, Kovac, Mihael
Format: Preprint
Published: 2026
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917383012089856
author Smolic, Ema
Brcic, Mario
Hobor, Luka
Kovac, Mihael
author_facet Smolic, Ema
Brcic, Mario
Hobor, Luka
Kovac, Mihael
contents Many software systems originate as prototypes or minimum viable products (MVPs), developed with an emphasis on delivery speed and responsiveness to changing requirements rather than long-term code maintainability. While effective for rapid delivery, this approach can result in codebases that are difficult to modify, presenting a significant opportunity cost in the era of AI-assisted or even AI-led programming. In this paper, we present a case study of using coding models for automated unit test generation and subsequent safe refactoring, with proposed code changes validated by passing tests. The study examines best practices for iteratively generating tests to capture existing system behavior, followed by model-assisted refactoring under developer supervision. We describe how this workflow constrained refactoring changes, the errors and limitations observed in both phases, the efficiency gains achieved, when manual intervention was necessary, and how we addressed the weak value misalignment we observed in models. Using this approach, we generated nearly 16,000 lines of reliable unit tests in hours rather than weeks, achieved up to 78\% branch coverage in critical modules, and significantly reduced regression risk during large-scale refactoring. These results illustrate software engineering's shift toward an empirical science, emphasizing data collection and constraining mechanisms that support fast, safe iteration.
format Preprint
id arxiv_https___arxiv_org_abs_2604_03135
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle AI-Assisted Unit Test Writing and Test-Driven Code Refactoring: A Case Study
Smolic, Ema
Brcic, Mario
Hobor, Luka
Kovac, Mihael
Software Engineering
Artificial Intelligence
Many software systems originate as prototypes or minimum viable products (MVPs), developed with an emphasis on delivery speed and responsiveness to changing requirements rather than long-term code maintainability. While effective for rapid delivery, this approach can result in codebases that are difficult to modify, presenting a significant opportunity cost in the era of AI-assisted or even AI-led programming. In this paper, we present a case study of using coding models for automated unit test generation and subsequent safe refactoring, with proposed code changes validated by passing tests. The study examines best practices for iteratively generating tests to capture existing system behavior, followed by model-assisted refactoring under developer supervision. We describe how this workflow constrained refactoring changes, the errors and limitations observed in both phases, the efficiency gains achieved, when manual intervention was necessary, and how we addressed the weak value misalignment we observed in models. Using this approach, we generated nearly 16,000 lines of reliable unit tests in hours rather than weeks, achieved up to 78\% branch coverage in critical modules, and significantly reduced regression risk during large-scale refactoring. These results illustrate software engineering's shift toward an empirical science, emphasizing data collection and constraining mechanisms that support fast, safe iteration.
title AI-Assisted Unit Test Writing and Test-Driven Code Refactoring: A Case Study
topic Software Engineering
Artificial Intelligence
url https://arxiv.org/abs/2604.03135