In API testing, deriving logical constraints on API response bodies to be used as oracles is crucial for generating test cases and performing automated testing of RESTful APIs. However, existing approaches are restricted to dynamic analysis, in which oracles are extracted via the execution of APIs as part of the system under test. In this paper, we propose a complementary LLM-based static approach in which constraints for API response bodies are mined from API specifications. We leverage large language models (LLMs) to comprehend API specifications, mine constraints for response bodies, and generate test cases. To reduce LLM hallucination, we apply an Observation-Confirmation (OC) scheme that uses initial prompts to contextualize constraints, allowing subsequent prompts to more accurately confirm their presence. Our empirical results show that RBCTest with OC prompting achieves high precision in constraint mining, with averages ranging from 85.1% to 93.6%. It also performs well in generating test cases from mined constraints, with precision ranging from 86.4% to 91.7%. We further use test cases generated by RBCTest to detect 46 mismatches between API specifications and actual response data across 19 real-world APIs. Four of these mismatches were reported in developers' forums.


翻译:在API测试中,推导API响应体的逻辑约束作为预言机制,对于生成测试用例和执行RESTful API的自动化测试至关重要。然而,现有方法局限于动态分析,即通过执行被测系统中的API来提取预言机制。本文提出一种基于大型语言模型(LLM)的互补性静态方法,从API规范中挖掘响应体约束。我们利用大型语言模型理解API规范、挖掘响应体约束并生成测试用例。为减少LLM幻觉,我们采用观察-确认(OC)方案:通过初始提示对约束进行语境化处理,使后续提示能更准确地确认其存在性。实验结果表明,采用OC提示的RBCTest在约束挖掘中实现了高精度,平均精度范围达85.1%至93.6%。在基于挖掘约束生成测试用例方面也表现优异,精度范围达86.4%至91.7%。我们进一步使用RBCTest生成的测试用例,在19个真实API中检测出46处API规范与实际响应数据的不匹配现象,其中4处不匹配已在开发者论坛中被报告。

0
下载
关闭预览

相关内容

应用程序接口(简称 API),又称为应用编程接口,就是软件系统不同组成部分衔接的约定。
AAAI 2022 | ProtGNN:自解释图神经网络
专知会员服务
40+阅读 · 2022年2月28日
AAAI 2022 | ProtGNN:自解释图神经网络
专知
10+阅读 · 2022年2月28日
【ICML2021】因果匹配领域泛化
专知
12+阅读 · 2021年8月12日
【NeurIPS2019】图变换网络:Graph Transformer Network
NAACL 2019 | 一种考虑缓和KL消失的简单VAE训练方法
PaperWeekly
20+阅读 · 2019年4月24日
国家自然科学基金
0+阅读 · 2017年12月31日
国家自然科学基金
17+阅读 · 2017年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
相关资讯
AAAI 2022 | ProtGNN:自解释图神经网络
专知
10+阅读 · 2022年2月28日
【ICML2021】因果匹配领域泛化
专知
12+阅读 · 2021年8月12日
【NeurIPS2019】图变换网络:Graph Transformer Network
NAACL 2019 | 一种考虑缓和KL消失的简单VAE训练方法
PaperWeekly
20+阅读 · 2019年4月24日
相关基金
国家自然科学基金
0+阅读 · 2017年12月31日
国家自然科学基金
17+阅读 · 2017年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员