Page 265 - 《软件学报》2026年第4期
P. 265
1706 软件学报 2026 年第 37 卷第 4 期
Please summarize and understand the main content of the issue based on the issue title and description, analyze the
reasons for the issue, the expected normal performance of the issue and how to test it, and finally write one test case to
test whether the bug has been fixed.
## Tips
1. You should generate test case based on the given issue_title, issue_description and context.
2. The given ##Example Tests are test cases that may be related to the issue. You can refer to it.
3. When necessary, you can import some libraries or APIs from ## Imports List.
4. The generated test case must be a class.
5. Please use the special code format for code snippet.
6. If you call some APIs, please pay attention to the data type of the parameters.
本文的 prompt 2 模板需要填充 5 个字段, 分别是 issue_title、issue_description、bug_context、imports_list 和
example_tests. 这些字段对应于问题报告的标题、描述、报错根函数、import 语句以及测试用例样本. 其中, 问题报
告标题和描述来自 SWE-bench Lite 数据集中每个问题报告的基本信息, 而报错根函数、import 语句和测试用例样
本则是基于给定问题报告和代码仓库检索出的信息. 在所有字段填充完成后, 本文利用 OpenAI 提供的 API 接口, 调
用 GPT-4 模型生成 5 个格式化为类的测试用例, 以实现针对特定问题报告的故障复现测试用例自动生成.
图 8 展示了大语言模型生成的故障复现测试用例, 针对的是上文提到的 Django 仓库中的问题报告, 标题为
“URLField 报错内容有误”. 图中展示的两个测试用例均由大语言模型直接生成, 并成功复现问题报告并验证问题报
告是否得到解决. 生成的测试用例 1 首先定义了一个 URLField 类, 然后设计了一个非法 URL 字符串“'////]@N.AN'”,
并将其传入 clean 函数, 期望模型输出 ValidationError. 这一测试用例有效复现了问题报告中遇到非法 URL 的场景,
并通过断言方式验证问题报告是否正确解决, 构成了一个正确的故障复现测试用例. 生成的测试用例 2 与测试用例 1
的整体结构相似, 但额外定义了一个 expected_error_message 变量, 内容为 “'Enter a valid URL.'”, 进一步优化了错误
输出格式. 这不仅要求测试结果能返回 ValidationError, 还添加了错误原因, 即输入了非法 URL. 这两个测试用例成
功实现了面向 GitHub 问题报告的自动化故障复现测试用例生成任务, 展示了大语言模型在这一领域的有效性.
图 8 大语言模型生成的故障复现测试用例

