针对自动测试工具在深度学习框架上效果不佳的问题,提出 MUTester,利用从 API 文档和 Stack Overflow 代码片段中挖掘的 API 约束与使用模式指导测试生成,使代码覆盖率平均提升 15.7%-27.0%,并减少约 19.0% 的无效测试。
摘要:
许多能够生成对程序具有高覆盖率的单元测试用例的自动单元测试生成工具已被提出。然而,大多数这些工具在深度学习(DL)框架上效果不佳,因为许多深度学习 API 期望输入遵循特定的 API 知识。为了填补这一空白,我们提出了 MUTester,通过利用从相应 API 文档中挖掘的 API 约束和从 Stack Overflow(SO)中的代码片段挖掘的 API 使用模式,为深度学习框架的 API 生成单元测试用例。具体而言,我们首先提出了一组 18 条规则,用于从 API 文档中挖掘 API 约束。然后,我们使用频繁项集挖掘技术,从收集自 SO 的大规模机器学习 API 相关代码片段语料库中挖掘 API 使用模式。最后,我们使用上述两类 API 知识来指导现有测试生成器对深度学习框架的测试生成。为了评估 MUTester 的性能,我们首先从四个广泛使用的深度学习框架(即 Scikit-learn、PyTorch、TensorFlow 和 CNTK)中收集了 1,971 个 API,并且对于每个 API,我们进一步提取其 API 知识,即 API 约束和 API 使用。给定一个 API,MUTester 将其 API 知识与现有的测试生成器(例如,基于搜索的测试生成器 PyEvosuite 和随机测试生成器 PyRandoop)相结合,以生成测试用例来测试该 API。我们的实验结果表明,MUTester 能够显著改进相应的测试生成方法,代码覆盖率平均提升 15.7% 至 27.0%。此外,它还可以帮助减少现有测试生成器生成的约 19.0% 的无效测试。我们对 16 名开发者的用户研究进一步证明了 MUTester 在为深度学习框架生成测试用例方面的实用性。
英文摘要:
Many automatic unit test generation tools that can generate unit test cases with high coverage over a program have been proposed. However, most of these tools are ineffective on deep learning (DL) frameworks due to the fact that many of deep learning APIs expect inputs that follow specific API knowledge. To fill this gap, we propose MUTester to generate unit test cases for APIs of deep learning frameworks by leveraging the API constraints mined from the corresponding API documentation and the API usage patterns mined from code fragments in Stack Overflow (SO). Particularly, we first propose a set of 18 rules for mining API constraints from the API documents. We then use the frequent itemset mining technique to mine the API usage patterns from a large corpus of machine learning API related code fragments collected from SO. Finally, we use the above two types of API knowledge to guide the test generation of existing test generators for deep learning frameworks. To evaluate the performance of MUTester, we first collect 1,971 APIs from four widely-used deep learning frameworks (i.e., Scikit-learn, PyTorch, TensorFlow, and CNTK) and for each API, we further extract its API knowledge, i.e., API constraints and API usage. Given an API, MUTester combines its API knowledge with existing test generators (e.g., search-based test generator PyEvosuite and random test generator PyRandoop) to generate test cases to test the API. Results of our experiment show that MUTester can significantly improve the corresponding test generation methods and the improvement in code coverage is 15.7% to 27.0% on average. In addition, it can help reduce around 19.0% of invalid tests generated by the existing test generators. Our user study with 16 developers further demonstrates the practicality of MUTester in generating test cases for deep learning frameworks.
Automatically Identifying Parameter Constraints in Complex Web APIs: A Case Study at Adyen
Web API可能对参数有约束,因此并非所有参数都是必需的或可选的。此外,一个参数的存在或值可能会导致需要另一个参数,或者参数可能会限制哪些类型的值是有效的。对约束有一个清晰的概述有助于API消费者在不需要额外支持的情况下进行集成,并减少集成错误。我们利用现有的文档和代码分析方法来识别复杂Web API中的参数约束。在本文中,我们报告了Adyen的几个API的案例研究,Adyen是一家大型支付公司,为客户提供复杂的Web API。我们的研究结果表明,文档和代码为基础的方法可以识别23%和53%的约束,分别,当结合起来,68%。我们还反思了这些方法目前面临的挑战。特别是,缺乏明确描述文档中(文档分析中)约束的信息,以及对数据流敏感的合理静态代码分析器的工程设计,在整个API代码中保持更长的参数引用,并且能够象征性地执行API使用的几个库和框架(静态分析中)。
RACK: Automatic API Recommendation using Crowdsourced Knowledge
传统的代码搜索引擎通常不能很好地执行自然语言查询,因为它们主要应用关键字匹配。因此,这些引擎需要精心设计的查询,其中包含有关代码搜索编程API的信息。不幸的是,现有的研究表明,准备一个有效的代码搜索查询是既具有挑战性和耗时的开发人员。在本文中,我们提出了一种新的API推荐技术--RACK,它通过利用Stack Overflow的众包知识中的关键字-API关联,为代码搜索的自然语言查询推荐相关API列表。我们首先使用11个核心Java包和来自Stack Overflow的344 K Java帖子进行探索性研究来激励我们的技术。使用150个代码搜索查询随机选择的三个Java教程网站的实验表明,我们的技术建议正确的API类的前10名的结果约79%的查询,这是非常有前途的。与最先进技术的两个变体的比较还表明,RACK不仅在Top-K准确率方面,而且在平均平均精确率和平均召回率方面都大大优于它们。
APITestGenie: Generating Web API Tests from Requirements and API Specifications with LLMs
Deloitte(德勤);Faculty of Engineering, University of Porto(波尔图大学工程学院);LIACC, Faculty of Engineering, University of Porto(波尔图大学工程学院 LIACC);INESC TEC, Faculty of Engineering, University of Porto(波尔图大学工程学院 INESC TEC)
University of Buenos Aires(布宜诺斯艾利斯大学);CONICET(阿根廷国家科学研究委员会);Kristiania University of Applied Sciences(克里斯蒂亚纳应用科学大学);Oslo Metropolitan University(奥斯陆都会大学);Volkswagen AG(大众汽车集团)
When Specifications Meet Reality: Uncovering API Inconsistencies in Ethereum Infrastructure
Beihang University(北京航空航天大学);Zhongguancun Laboratory(中关村实验室);The Hong Kong Polytechnic University(香港理工大学);Beijing Institute of Technology(北京理工大学);Amber Group(安比集团);Huazhong University of Science and Technology(华中科技大学)
Mitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decoding
Technische Universität Darmstadt(德累斯顿技术大学);Hessian Center for Artificial Intelligence (hessian.AI)(黑森人工智能中心);Pariton AI;National Research Center for Applied Cybersecurity ATHENE(应用网络安全国家研究中心ATHENE)
Evaluating LLMs on Sequential API Call Through Automated Test Generation
The University of Tokyo(东京大学);Macau University of Science and Technology(澳门科技大学);Shandong University(山东大学);Hong Kong University of Science and Technology(香港科技大学);Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所);University of Alberta(阿尔伯塔大学)