arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2404.13340cs.SEcs.AI
收藏

大型语言模型作为测试用例生成器:性能评估与增强

Large Language Models as Test Case Generators: Performance Evaluation and Enhancement

Beihang University(北京航空航天大学)

Kefan Li, Yuan Yuan

AI总结:

针对大型语言模型在复杂问题上生成测试用例性能下降的问题,提出多智能体框架TestChain,通过解耦测试输入输出并利用ReAct与Python交互,显著提升了测试用例准确率。

摘要:

使用大型语言模型(LLMs)进行代码生成已被广泛研究并取得了显著进展。作为代码生成的补充方面,测试用例生成在确保代码质量和可靠性方面至关重要。然而,将LLMs作为测试用例生成器的探索要少得多。目前的这条研究路线主要集中在利用LLMs生成的测试用例来辅助增强代码生成,而LLMs单独在测试用例生成方面的性能尚未得到全面考察。为了弥补这一空白,我们进行了广泛的实验,研究LLMs能否生成高质量的测试用例。我们发现,随着问题难度的增加,最先进的LLMs难以生成正确的测试用例,这在很大程度上是由于它们在计算和推理方面存在固有限制。为了缓解这一问题,我们进一步提出了一个名为TestChain的多智能体框架,该框架将测试输入和测试输出的生成解耦。值得注意的是,TestChain使用ReAct格式对话链让LLMs与Python解释器进行交互,以提供更准确的测试输出。我们的结果表明,TestChain大幅优于基线。特别是在测试用例的准确率方面,使用GPT-4作为骨干的TestChain在LeetCode-hard数据集上比基线提高了13.84%。

英文摘要:

Code generation with Large Language Models (LLMs) has been extensively studied and achieved remarkable progress. As a complementary aspect to code generation, test case generation is of crucial importance in ensuring the quality and reliability of code. However, using LLMs as test case generators has been much less explored. Current research along this line primarily focuses on enhancing code generation with assistance from test cases generated by LLMs, while the performance of LLMs in test case generation alone has not been comprehensively examined. To bridge this gap, we conduct extensive experiments to study how well LLMs can generate high-quality test cases. We find that as the problem difficulty increases, state-of-the-art LLMs struggle to generate correct test cases, largely due to their inherent limitations in computation and reasoning. To mitigate this issue, we further propose a multi-agent framework called \emph{TestChain} that decouples the generation of test inputs and test outputs. Notably, TestChain uses a ReAct format conversation chain for LLMs to interact with a Python interpreter in order to provide more accurate test outputs. Our results indicate that TestChain outperforms the baseline by a large margin. Particularly, in terms of the accuracy of test cases, TestChain using GPT-4 as the backbone achieves a 13.84\% improvement over the baseline on the LeetCode-hard dataset.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑