一句话:实证研究 LLM 能否重写 JUnit 单元测试以降低能耗,同时保持测试有效性。
软件测试对保障可靠性至关重要,但由于开发者频繁验证与持续集成等实践,测试套件常被反复执行,带来可观的能耗与环境影响。本文开展一项探索性实证研究,考察当前大语言模型(LLM)能否对单元测试进行重构,在维持测试有效性的前提下提升其能源效率。作者采用直接提示的方式,让 LLM 对 JUnit 单元测试进行能源重构,并测量重构前后的能耗与测试有效性。结果显示,仅有小部分单元测试实现了能源效率提升,且对测试有效性的影响可以忽略。随后,作者进一步分析了能源重构测试数量偏少的潜在原因,发现 StackOverflow、GitHub 等主流平台上与能源效率相关的信息较为稀缺,这种信息匮乏可能影响 LLM 在该主题上的训练效果。
Software testing is essential to ensure the reliability of software. To that end, test suites are often executed repeatedly, due to frequent developer validation runs, and practices like continuous integration. This repeated execution leads to substantial energy consumption and thus potential environmental impact. In this paper, we conduct an exploratory study to examine whether current Large Language Models (LLMs) are capable of reengineering unit tests to improve their energy efficiency while maintaining test effectiveness. Our results indicate that, using a straightforward prompt, only a small subset of unit tests shows improved energy efficiency, with negligible impact on test effectiveness. Subsequently, we scrutinize our results for potential reasons for the relatively low number of energy-reengineered unit tests. We observe that energy efficiency related information is scarce on prominent platforms like StackOverflow and GitHub. This scarcity of information potentially affects how LLMs can be trained on the topic of energy efficiency.