AI-Assisted Unit Test Writing and Test-Driven Code Refactoring: A Case Study
Ema Smolic, Mario Brcic, Luka Hobor, Mihael Kovac

TL;DR
This case study demonstrates how AI models can automate unit test creation and safe code refactoring, significantly accelerating development and reducing regression risks in software engineering.
Contribution
The paper presents a workflow for AI-assisted automated testing and refactoring, highlighting best practices, limitations, and efficiency gains in a real-world case study.
Findings
Generated nearly 16,000 lines of unit tests in hours
Achieved up to 78% branch coverage in critical modules
Reduced regression risk during large-scale refactoring
Abstract
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…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
