AI-Assisted Unit Test Writing and Test-Driven Code Refactoring: A Case Study
Not on the map. Why?
Abstract (arXiv)
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.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 13 of its 29 references that are in the map. First posted on arXiv 3 Apr 2026.
Builds on
13 of 29 references.
References · 13
- 2023An Empirical Evaluation of Using Large Language Models for Automated Unit Test Generationcited by 194
- 2023Self-planning Code Generation with Large Language Modelscited by 124
- 2022Large Language Models are Few-shot Testers: Exploring LLM-based General Bug Reproductioncited by 111
- 2023ChatUniTest: A Framework for LLM-Based Test Generationcited by 96
- 2024Code-Aware Prompting: A study of Coverage Guided Test Generation in Regression Setting using LLMcited by 64
- 2023Refactoring Programs Using Large Language Models with Few-Shot Examplescited by 28
- 2024An Empirical Study on the Code Refactoring Capability of Large Language Modelscited by 19
- 2023LLM4VV: Developing LLM-Driven Testsuite for Compiler Validationcited by 15
- 2021Impossibility Results in AI: A Surveycited by 13
- 2025MANTRA: Enhancing Automated Method-Level Refactoring with Contextual RAG and Multi-Agent LLM Collaborationcited by 10
- 2025LLM-based Multi-Agent System for Intelligent Refactoring of Haskell Codecited by 3
- 2024Optimizing AI-Assisted Code Generationcited by 2
Built on by
Not cited yet.