一句话:提出 UTFix,用 LLM 结合静态/动态代码切片与失败信息,修复因代码变更而过时的单元测试,恢复断言与覆盖率。
现代软件频繁更新,测试套件却常随之过时。Meta 的研究显示 14%–22% 的软件故障源于未能反映代码变更的过时测试。本文提出 UTFix,一种在焦点方法发生变更时自动修复单元测试的方法,针对变更引起的断言失败与代码覆盖率下降两个问题。UTFix 向语言模型提供静态代码切片、动态代码切片和失败消息等上下文信息来完成测试修复。作者构建了合成基准 Syn-Bench 和真实世界基准进行评估:在 Syn-Bench 上修复了 89.2% 的断言失败,369 个单元测试中 96 个达到 100% 覆盖率;在真实基准上修复了 60% 的断言失败,30 个单元测试中 19 个达到 100% 覆盖率。据作者所知,这是首个面向演化中 Python 项目的单元测试修复综合研究。
Software updates, including bug repair and feature additions, are frequent in modern applications but they often leave test suites outdated, resulting in undetected bugs and increased chances of system failures. A recent study by Meta revealed that 14%-22% of software failures stem from outdated tests that fail to reflect changes in the codebase. This highlights the need to keep tests in sync with code changes to ensure software reliability. In this paper, we present UTFix , a novel approach for repairing unit tests when their corresponding focal methods undergo changes. UTFix addresses two critical issues: assertion failure and reduced code coverage caused by changes in the focal method. Our approach leverages language models to repair unit tests by providing contextual information such as static code slices, dynamic code slices, and failure messages. We evaluate UTFix on our generated synthetic benchmark (Syn-Bench), and real-world benchmark. In our experiment, UTFix successfully repaired 89.2% of assertion failures and achieved 100% code coverage for 96 tests out of 369 unit tests. On the real-world benchmarks, UTFix repaired 60% of assertion failures while achieving 100% code coverage for 19 out of 30 unit tests. To the best of our knowledge, this is the first comprehensive study focused on unit test in evolving Python projects. Our contributions include the development of UTFix , the creation of Syn-Bench and real-world benchmarks, and the demonstration of the effectiveness of LLM-based methods in addressing unit test failures due to software evolution.
@article{paperbot3197,
title = {UTFix: Change Aware Unit Test Repairing using LLM},
author = {Shanto Rahman and Sachit Kuhar and Berk Cirisci and Pranav Garg and Shiqi Wang and Xiaofei Ma and Anoop Deoras and Baishakhi Ray},
journal = {Proceedings of the ACM on Programming Languages},
volume = {9},
number = {OOPSLA1},
year = {2025},
doi = {10.1145/3720419}
}