如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

huangapple go评论71阅读模式
英文:

How to handle multiple mock response templates while designing a simple Mobile mock API testing system

问题

I can help you with the translation. Here's the translated content:

有一个支持iOS、Android和Windows的应用程序,拥有许多Web服务,每个Web服务都有不同的响应模板,根据输入不同而不同。

因此,基本上我们想要在移动应用程序中运行不同的模拟场景,以便轻松捕获回归问题,并且在服务器宕机时可以使用模拟系统。

因此,URL具有绝对URL和相对URL,例如:

https://www.test.com/myapp/getartcollection

所以在这里,
https://www.test.com是绝对URL
/myapp/getartcollection是相对URL。

我可以在构建URL时使用条件标志将绝对URL更改为自己的自定义Web服务器URL/IP或本地主机。

服务器系统可以具有诸如Java、Ruby、PHP或Dot net等一种Web服务器语言。

在哪里存储模拟响应模板才是正确的位置?

  1. 作为移动应用程序的一部分,并在请求中添加一个参数,其中包含预期响应的内容以及请求的URL,服务器语言可以读取该参数并响应客户端。

  2. 或者我可以在服务器上具有某种文件夹结构,每个文件夹中都有相关的API响应模板存储在其中,以便具有适当权限的任何人都可以通过FTP进行更改响应(JSON或XML),以满足预期。

  3. 那么,保持不同响应模板有组织的最佳方法是什么,是按照URL中的不同目录进行组织,还是可以将所有内容都放在一个目录中,只需在请求URL的标题字段中发送“responseTemplateName”,并使用文件名来搜索一个单一目录中的响应模板。

是否有行业标准或建议?

与此相关的任何建议都非常受欢迎。

移动端点:
iOS、Android和Windows。

英文:

There's an app that's in iOS, Android and Windows and that has plenty of web services and each web service has different response templates based on the input.

So basically we'd like to run different mock scenarios for testing in mobile app so we can easily catch regression issues and we can use mock system when server is down

So the URLs have absolute and relative URL for example.

https://www.test.com/myapp/getartcollection

So here
https://www.test.com is an absolute URL
/myapp/getartcollection is a relative URL.

I can change the absolute URL to my own custom web server URL/IP or localhost by using conditional flags while building the URL.

The server system can have one of the web server languages like Java or Ruby or PHP or Dot net etc..

What would be the right place to store the Mock response templates?

  1. as a part of mobile app and add a parameter in the request which has the contents of expected response and the requesting URL server language can read the parameter and respond to the client with that.

  2. or I can have certain folder structure in server and each folder has related API response templates stored in it so anyone with right permission can FTP it and change the response (JSON or XML) according to the expectation.

  3. So what's the best way to keep different response templates organised is it by following different directories as in the URL or can we have everything in one directory and just send the responseTemplateName as header-field in request URL and use the filename to search the response template in one single directory.

Is there any industry standard or recommendations?

Any suggestion related anything to do with this is very welcome.

Mobile end points:
iOS, Android and Windows.

答案1

得分: 2

  • 我认为首先,你必须创建一个模拟服务器,可以充当代理,将来自移动端点的请求转发到模拟服务器到实际服务器,并将实际服务器的响应发送回以在模拟服务器中保留响应的副本,并将其发送回移动端。

  • 在转发请求时,您必须记录API请求和响应,以您喜欢的方式,如数据库或本地文件。

  • 然后,每当移动端发出请求时,将请求与期望进行匹配,并直接从模拟服务器发送响应,如果没有匹配,则让请求传递到实际服务器并到上述。

  • 如果您想要自己开发整个系统,那么您必须选择一种服务器端编程语言,如Python或PHP等,并准备好Web服务器,可能还必须选择像MySQL或Oracle这样的数据库来存储响应。

  • 您必须自己编写逻辑,以查看是否可以将现有的可用响应之一发送回移动设备,或者在移动设备和实际服务器之间(在记录时)充当代理。

  • 这种记录、模拟或转发/返回方法非常灵活、可扩展且耗时较少。

如果您想使用预先构建的模拟服务器,请随时查看以下热门产品。

更新:

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板
如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

建议:

  1. 使用免费的开源Php作为模拟服务器
  2. 使用免费的MySQL作为模拟服务器的数据库

您还可以选择其他选项,例如Python和AWS等。

建议的用户界面:(希望用户界面很明显,简化说明)

您可以选择要发送回的已记录响应之一。请查看建议的数据库架构中的数据映射方式

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

您可以添加新的API及其可能的响应或编辑已添加的API

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

建议的数据库架构:

数据库架构图显示了表之间的主键和外键关系,设计时应遵循数据库规范化的基本规则。

希望该架构相当容易理解

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

P.S:

我会仔细考虑并尝试添加任何缺失的信息,以构建一个完整的模拟服务器。

英文:
  • I think first, you have to create a mock server which can act as proxy like forward the request that comes from mobile end-point to mock server to actual server and send back the response from actual server to keep a copy of the response in mock server and send it back to mobile

  • While forwarding the requests you have to record the API requests and responses in the medium of your preference like DB or locally as file.

  • Then whenever a request comes from mobile then match the request with expectation and send back the response right from mock server itself and if there's no match then let the request pass to actual server and to the above.

  • If you would like to develop whole thing on your own then you have to choose a server side programming language like python or php etc.. and get the web server ready , probably you have to choose the DB like mysql or oracle to store the responses.

  • You have to code the logic on your own to see if you can send back one of the existing available responses back to the mobile or become a proxy ( while recording ) between mobile and actual server.

  • This kind of record , mock or forward/return approach is quite flexible, scalable and less time consuming.

If you would like to go with prebuilt mock servers then feel free to dig into the following popular products.

Update:

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板
如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

Recommendation:

  1. use free open source Php for mock server
  2. use free mysql as db for mock server

you have other options as well like python and aws etc..

Proposed UI: (Hope the UI would be obvious and cut down the explanation)

You can choose one of the recorded responses as the one that needs to be sent back. Please see how the data is mapped in the proposed DB schema

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

You can add new API and it's probable responses or edit the added one

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

Proposed DB schema:

The DB schema diagram shows the Primary key and foreign key relationship between tables and it's always good to apply DB normalisation thumb rules while designing it.

Hope the schema is quite self explanatory

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

如何在设计简单的移动模拟API测试系统时处理多个模拟响应模板

P.S:

I will think through and try to add any missing information to build a full fledged mock server

huangapple
  • 本文由 发表于 2023年6月1日 04:46:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76377158.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定