[论文解读] ChatGPT vs SBST: A Comparative Assessment of Unit Test Suite Generation
该论文比较由 ChatGPT 和 EvoSuite (SBST) 生成的单元测试用例在正确性、可读性、代码覆盖率和缺陷检测方面的表现,揭示了 ChatGPT 在测试多样性与真实感方面的优势,但也凸显了编译与覆盖率方面的不足。
Recent advancements in large language models (LLMs) have demonstrated exceptional success in a wide range of general domain tasks, such as question answering and following instructions. Moreover, LLMs have shown potential in various software engineering applications. In this study, we present a systematic comparison of test suites generated by the ChatGPT LLM and the state-of-the-art SBST tool EvoSuite. Our comparison is based on several critical factors, including correctness, readability, code coverage, and bug detection capability. By highlighting the strengths and weaknesses of LLMs (specifically ChatGPT) in generating unit test cases compared to EvoSuite, this work provides valuable insights into the performance of LLMs in solving software engineering problems. Overall, our findings underscore the potential of LLMs in software engineering and pave the way for further research in this area.
研究动机与目标
- 评估 ChatGPT 是否能够为 Java 方法生成正确的单元测试。
- 评估 ChatGPT 生成的测试用例的可读性与可维护性。
- 将 ChatGPT 生成的测试用例的代码覆盖率与 EvoSuite(SBST)进行比较。
- 用静态分析衡量 ChatGPT 生成的测试用例的缺陷检测能力。
提出的方法
- 以 EvoSuite 作为 Java 单元测试生成的 SBST 基线。
- 用标准化提示对代码片段进行提示,让 ChatGPT 生成 JUnit 测试用例。
- 通过编译/执行测试并使用 SpotBugs 进行缺陷分析来评估正确性。
- 通过代码风格检查(Checkstyle)和复杂度指标(圈复杂度、认知复杂度)来衡量可读性。
- 使用 JaCoCo 指令/语句覆盖率来评估代码覆盖率,并比较各对象的平均值。

实验结果
研究问题
- RQ1RQ1 正确性:ChatGPT 的单元测试用例建议是否正确?
- RQ2RQ2 可读性:ChatGPT 生成的测试用例集有多易于理解?
- RQ3RQ3 代码覆盖率:与 SBST 相比,ChatGPT 的代码覆盖率表现如何?
- RQ4RQ4 缺陷检测:ChatGPT 与 SBST 在生成可检测缺陷的测试方面有多有效?
主要发现
- 在应用长输入约束后,分析了 75 个项目中的 207 个 Java 类。
- 69.6% 的 ChatGPT 生成的测试在没有人工干预的情况下编译并执行。
- SpotBugs 在 204 个测试用例中发现了 403 个潜在缺陷(其中 3 个原本无法编译)。
- 61.2% 的 ChatGPT 生成的测试用例无缺陷;9.8% 的测试用例存在最高/严重优先级的缺陷。
- Evosuite 的平均语句覆盖率高于 ChatGPT(74.2% 对 55.4%),而 ChatGPT 在 207 个类中的 37 个、在 75 个项目中的 10 个上超越 EvoSuite。

更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。