大型语言模型能否编写良好的基于属性的测试?
Can Large Language Models Write Good Property-Based Tests?
AI总结:
本研究探索用大型语言模型通过两种提示技术自动合成基于属性的测试,提出有效性、健全性和属性覆盖率等评估指标,在40个Python API方法上验证,最佳模型平均2.4个样本即可生成有效测试,属性覆盖率最高达21%。
摘要:
基于属性的测试(PBT)虽然在软件测试研究界是一种成熟的技术,但在实际软件中仍然相对未被充分利用。编写基于属性的测试的痛点包括实现多样化的随机输入生成器以及思考有意义的属性进行测试。然而,开发人员更倾向于编写文档;大量的库API文档可用,并可作为PBT的自然语言规范。由于大型语言模型(LLMs)最近在各种编码任务中展现出潜力,我们研究使用现代LLMs通过两种提示技术自动合成PBT。一个关键挑战是严格评估LLM合成的PBT。我们提出了一种方法论,考虑生成测试的几个属性:(1)有效性,(2)健全性,以及(3)属性覆盖率,这是一种新颖的度量,通过生成属性突变体来衡量PBT检测属性违反的能力。在我们对三个模型(GPT-4、Gemini-1.5-Pro、Claude-3-Opus)的40个Python库API方法的评估中,我们发现使用最佳模型和提示方法,平均可以在2.4个样本中合成一个有效且健全的PBT。我们还发现,我们用于确定PBT健全性的度量与人类对属性断言的判断一致,实现了100%的精确度和97%的召回率。最后,我们评估了LLMs在所有API方法中的属性覆盖率,发现最佳模型(GPT-4)能够自动为从API文档中可提取的属性的21%合成正确的PBT。
英文摘要:
Property-based testing (PBT), while an established technique in the software testing research community, is still relatively underused in real-world software. Pain points in writing property-based tests include implementing diverse random input generators and thinking of meaningful properties to test. Developers, however, are more amenable to writing documentation; plenty of library API documentation is available and can be used as natural language specifications for PBTs. As large language models (LLMs) have recently shown promise in a variety of coding tasks, we investigate using modern LLMs to automatically synthesize PBTs using two prompting techniques. A key challenge is to rigorously evaluate the LLM-synthesized PBTs. We propose a methodology to do so considering several properties of the generated tests: (1) validity, (2) soundness, and (3) property coverage, a novel metric that measures the ability of the PBT to detect property violations through generation of property mutants. In our evaluation on 40 Python library API methods across three models (GPT-4, Gemini-1.5-Pro, Claude-3-Opus), we find that with the best model and prompting approach, a valid and sound PBT can be synthesized in 2.4 samples on average. We additionally find that our metric for determining soundness of a PBT is aligned with human judgment of property assertions, achieving a precision of 100% and recall of 97%. Finally, we evaluate the property coverage of LLMs across all API methods and find that the best model (GPT-4) is able to automatically synthesize correct PBTs for 21% of properties extractable from API documentation.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。