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.


翻译:许多软件系统最初以原型或最小可行产品(MVP)的形式开发,其开发重点在于交付速度和对不断变化需求的响应能力,而非长期代码可维护性。虽然这种方法有助于快速交付,但可能导致代码库难以修改,在AI辅助甚至AI主导编程的时代,这构成了巨大的机会成本。本文通过案例研究,探讨了如何使用编码模型自动生成单元测试并随后进行安全重构,同时通过测试通过率验证代码修改的有效性。研究考察了迭代生成测试以捕获现有系统行为的最佳实践,随后在开发者监督下进行模型辅助重构。我们描述了该工作流程如何约束重构变更、两个阶段中观察到的错误与局限性、实现的效率提升、需要人工干预的情况,以及如何解决模型中观察到的弱价值偏差问题。采用该方法,我们在数小时内(而非数周内)生成了近1.6万行可靠的单元测试代码,关键模块的分支覆盖率高达78%,并在大规模重构过程中显著降低了回归风险。这些结果展示了软件工程向实证科学的转变,强调数据收集和约束机制对支持快速安全迭代的重要性。

0
下载
关闭预览

相关内容

AI生成代码缺陷综述
专知会员服务
17+阅读 · 2025年12月8日
《软件定义网络元素与机器代码的形式化验证》
专知会员服务
14+阅读 · 2025年11月18日
【新书】使用AI智能体构建应用程序
专知会员服务
61+阅读 · 2024年10月26日
【ETHZ博士论文】机器学习代码: 安全性与可靠性
专知会员服务
19+阅读 · 2024年10月25日
AI可解释性文献列表
专知
43+阅读 · 2019年10月7日
类脑计算的前沿论文,看我们推荐的这7篇
人工智能前沿讲习班
21+阅读 · 2019年1月7日
《软件方法》1-8章全部自测题更新内容
UMLChina
11+阅读 · 2018年3月26日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Arxiv
0+阅读 · 4月8日
VIP会员
相关主题
最新内容
美国从乌克兰无人机战争中学习经验
专知会员服务
5+阅读 · 6月21日
ICML 2026 | 面向视觉语言模型的语义鲁棒性认证
专知会员服务
2+阅读 · 6月21日
学习数据的几何:形状空间分析数学综述
专知会员服务
9+阅读 · 6月17日
定向能反无人机系统最新发展动态
专知会员服务
11+阅读 · 6月17日
相关基金
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员