Combining TSL and LLM to Automate REST API Testing: A Comparative Study
作者: Thiago Barradas, Aline Paes, Vânia de Oliveira Neves
分类: cs.SE, cs.AI
发布日期: 2025-09-05
备注: 10 pages, article computer science, software engineering, software testing, ia, llm
期刊: SBES 2025 39th Brazilian Symposium on Software Engineering
💡 一句话要点
提出RestTSLLM以自动化REST API测试,解决测试覆盖不足问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: REST API测试 自动化测试 大型语言模型 测试规范语言 软件质量保证 测试覆盖率 生成模型
📋 核心要点
- 现有的REST API测试方法面临着分布式系统复杂性和测试覆盖不足的挑战,导致高人工成本和未检测故障。
- 本文提出RestTSLLM方法,结合测试规范语言和大型语言模型,自动生成REST API测试用例,解决测试场景和输入数据定义问题。
- 实验结果显示,Claude 3.5 Sonnet等模型在生成REST API测试方面表现优异,成功率和测试覆盖率显著提升。
📝 摘要(中文)
有效执行REST API测试对开发团队来说仍然是一个重大挑战,主要由于分布式系统的复杂性、多种可能场景以及有限的测试设计时间。全面测试所有输入组合是不切实际的,常常导致未检测到的故障、高人工成本和有限的测试覆盖率。为了解决这些问题,本文提出了一种名为RestTSLLM的方法,该方法结合了测试规范语言(TSL)和大型语言模型(LLM),自动生成REST API的测试用例。该方法针对两个核心挑战:测试场景的创建和适当输入数据的定义。通过集成提示工程技术与自动化管道,评估多种LLM在从OpenAPI规范生成测试方面的能力。评估集中于成功率、测试覆盖率和变异分数等指标,系统比较模型性能。结果表明,表现最佳的LLM包括Claude 3.5 Sonnet、Deepseek R1、Qwen 2.5 32b和Sabia 3,其中Claude 3.5 Sonnet在所有指标上均优于其他模型,成为本研究中最适合该任务的模型。这些发现突显了LLM在基于API规范自动生成测试方面的潜力。
🔬 方法详解
问题定义:本文旨在解决REST API测试中的自动化生成问题,现有方法由于复杂性和场景多样性,往往导致测试覆盖不足和高人工成本。
核心思路:RestTSLLM方法结合了测试规范语言(TSL)与大型语言模型(LLM),通过自动化生成测试用例,旨在提高测试效率和覆盖率。
技术框架:该方法包括两个主要模块:首先是测试场景的创建,其次是输入数据的定义。通过集成提示工程技术,构建一个自动化管道来评估不同LLM的性能。
关键创新:最重要的创新在于将TSL与LLM结合,利用LLM的生成能力来自动化测试用例的生成,这与传统的手动测试设计方法有本质区别。
关键设计:在实验中,使用了多种LLM模型,并通过成功率、测试覆盖率和变异分数等指标进行评估,确保生成的测试用例具有高质量和有效性。具体的参数设置和损失函数设计在文中详细描述。
🖼️ 关键图片
📊 实验亮点
实验结果表明,Claude 3.5 Sonnet在所有评估指标上均优于其他模型,成功率和测试覆盖率显著提升,显示出其在REST API测试自动化中的优越性。这一发现为API测试的自动化提供了新的思路和方法。
🎯 应用场景
该研究的潜在应用领域包括软件开发、API测试和质量保证等。通过自动化测试用例生成,开发团队可以显著提高测试效率,降低人工成本,并提高软件质量。未来,该方法有望推广至其他类型的API和软件测试领域,进一步提升自动化水平。
📄 摘要(原文)
The effective execution of tests for REST APIs remains a considerable challenge for development teams, driven by the inherent complexity of distributed systems, the multitude of possible scenarios, and the limited time available for test design. Exhaustive testing of all input combinations is impractical, often resulting in undetected failures, high manual effort, and limited test coverage. To address these issues, we introduce RestTSLLM, an approach that uses Test Specification Language (TSL) in conjunction with Large Language Models (LLMs) to automate the generation of test cases for REST APIs. The approach targets two core challenges: the creation of test scenarios and the definition of appropriate input data. The proposed solution integrates prompt engineering techniques with an automated pipeline to evaluate various LLMs on their ability to generate tests from OpenAPI specifications. The evaluation focused on metrics such as success rate, test coverage, and mutation score, enabling a systematic comparison of model performance. The results indicate that the best-performing LLMs - Claude 3.5 Sonnet (Anthropic), Deepseek R1 (Deepseek), Qwen 2.5 32b (Alibaba), and Sabia 3 (Maritaca) - consistently produced robust and contextually coherent REST API tests. Among them, Claude 3.5 Sonnet outperformed all other models across every metric, emerging in this study as the most suitable model for this task. These findings highlight the potential of LLMs to automate the generation of tests based on API specifications.