arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2208.00264cs.SE
收藏

挖掘单元测试用例合成API使用实例

Mining unit test cases to synthesize API usage examples

Mohammad Ghafari, Konstantin Rubinov, Mohammad Mehdi Pourhashem K

摘要:

软件开发人员研究和重用现有的源代码,以了解如何正确使用应用程序编程接口(API)。然而,手动为给定API找到足够的代码示例是一项困难且耗时的活动。查找或生成示例的现有方法假定使用API的合理客户端代码集可用。这个假设不适用于新发布的API库,非广泛使用的API,也不适用于私有API。在这项工作中,我们重用了测试代码中自然存在的重要信息,以避免在其他客户端代码源不可用时缺乏API的使用示例。我们提出了一种自动识别每个单元测试用例中最具代表性的API使用的方法。然后,我们开发了一种方法来合成API使用的例子,通过提取相关的语句,代表这样的API的使用。我们比较了我们的方法的原型实现的输出,人类编写的例子和国家的最先进的方法。所获得的结果是令人鼓舞的,与我们的方法自动生成的例子是优于国家的最先进的方法和高度相似的手动构造的例子。

英文摘要:

Software developers study and reuse existing source code to understand how to properly use application programming interfaces (APIs). However, manually finding sufficient and adequate code examples for a given API is a difficult and a time-consuming activity. Existing approaches to find or generate examples assume availability of a reasonable set of client code that uses the API. This assumption does not hold for newly released API libraries, non-widely used APIs, nor private ones. In this work we reuse the important information that is naturally present in test code to circumvent the lack of usage examples for an API when other sources of client code are not available. We propose an approach for automatically identifying the most representative API uses within each unit test case. We then develop an approach to synthesize API usage examples by extracting relevant statements representing the usage of such APIs. We compare the output of a prototype implementation of our approach to both human-written examples and to a state-of-the-art approach. The obtained results are encouraging; the examples automatically generated with our approach are superior to the state-of-the-art approach and highly similar to the manually constructed examples.

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

↑