一句话:提出差分提示,引导 ChatGPT 关注正确与缺陷代码的细微差异,以发现引发失败的测试用例。
自动检测软件失败需要在大搜索空间中找到包含触发故障输入与错误执行断言的失败引发测试用例。本文研究 ChatGPT 等大语言模型能否解决该挑战,发现其直接生成失败引发测试的成功率较低(28.8%)。作者观察到,ChatGPT 在缺陷代码与正确版本相似时能够推断代码意图,于是提出 Differential Prompting:先利用推断意图合成可编译代码,再基于给定版本与合成代码之间的细微差异构造提示,引导模型生成失败引发测试。在 Quixbugs 与 Codeforces 上的评估显示,该方法成功率分别为 75.0% 和 66.7%,优于常规 ChatGPT 提示与 Pynguin 基线。
Automated detection of software failures is an important but challenging software engineering task. It involves finding in a vast search space the failure-inducing test cases that contain an input triggering the software fault and an oracle asserting the incorrect execution. We are motivated to study how far this outstanding challenge can be solved by recent advances in large language models (LLMs) such as ChatGPT. However, our study reveals that ChatGPT has a relatively low success rate (28.8%) in finding correct failure-inducing test cases for buggy programs. A possible conjecture is that finding failure-inducing test cases requires analyzing the subtle differences (nuances) between the tokens of a program's correct version and those for its buggy version. When these two versions have similar sets of tokens and attentions, ChatGPT is weak in distinguishing their differences. We find that ChatGPT can successfully generate failure-inducing test cases when it is guided to focus on the nuances. Our solution is inspired by an interesting observation that ChatGPT could infer the intended functionality of buggy code if it is similar to the correct version. Driven by the inspiration, we develop a novel technique, called Differential Prompting, to effectively find failure-inducing test cases with the help of the compilable code synthesized by the inferred intention. Prompts are constructed based on the nuances between the given version and the synthesized code. We evaluate Differential Prompting on Quixbugs (a popular benchmark of buggy programs) and recent programs published at Codeforces (a popular programming contest portal, which is also an official benchmark of ChatGPT). We compare Differential Prompting with two baselines constructed using conventional ChatGPT prompting and Pynguin (the state-of-the-art unit test generation tool for Python programs). Our evaluation results show that for programs of Quixbugs, Differential Prompting can achieve a success rate of 75.0% in finding failure-inducing test cases, outperforming the best baseline by 2.6X. For programs of Codeforces, Differential Prompting's success rate is 66.7%, outperforming the best baseline by 4.0X.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{LiZWTWCK23,
title = {Nuances are the Key: Unlocking ChatGPT to Find Failure-Inducing Tests with Differential Prompting},
author = {Tsz-On Li and Wenxi Zong and Yibo Wang and Haoye Tian and Ying Wang and Shing-Chi Cheung and Jeff Kramer},
booktitle = {ASE},
year = {2023},
doi = {10.1109/ase56229.2023.00089}
}