gpt4 book ai didi

json - 自动测试 Web API REST 服务

转载 作者:行者123 更新时间:2023-11-28 20:44:27 26 4
gpt4 key购买 nike

您为 REST 服务(基于 ASP.NET WebAPI)推荐什么样的测试/自动化测试?当然有单元测试,但除此之外,有必要确保在某个版本上线后,对该特定版本的任何进一步更改都会公开兼容的 json(我们假设向 json 添加新字段对于客户)。

最佳答案

对于 REST API 的测试,我使用 Robot Framework连同(伟大的)Requests library .

我想出了这样的测试:

*** settings ***
Library Collections
Library requests

*** test cases ***
simpleRequest
${result} = get http://echo.jsontest.com/framework/robot-framework/api/rest
Should Be Equal ${result.status_code} ${200}
${json} = Set Variable ${result.json()}
${framework} = Get From Dictionary ${json} framework
Should Be Equal ${framework} robot-framework
${api} = Get From Dictionary ${json} api
Should Be Equal ${framework} rest

我在 blog post 中提供了更多详细信息.

关于json - 自动测试 Web API REST 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18858594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com