gpt4 book ai didi

bdd - 无强制参数场景API测试,响应为错误码和消息

转载 作者:行者123 更新时间:2023-12-04 01:06:00 24 4
gpt4 key购买 nike

鉴于此 API:

{{base_url}}/json/1F/flightavailability/adults=1&departureairport=CRL&departuredate=20190509&destinationairport=CZL

除“成人”外,所有参数都是强制性的。我需要为他们编写一个 BDD 场景和步骤定义来自动化场景:如果缺少任何这些强制参数,响应应该是“422,未处理”。

最佳答案

在查看 BDD 场景时,我总是喜欢进行对话,即使是针对 API 而不是 UI。我想象对话会像这样进行:

Shobha: So you don't need to know how many adults are travelling toprocess this, but you do need departure airport, departure date anddestination airport?

Business: That's right. If we don't know how many adults aretravelling, we assume it's 1, and we give back the available flights,priced with 1 ticket. Otherwise, we show all available flights andprices for the number of adults travelling.

Tester: What if there are no flights on that date?

Business: Ah, then it should say there are no flights.

Tester: What if there's 2 adults travelling, but only 1 seat on theplane?

Business: Oh, good catch - well, we should filter that out too.

Shobha: OK, so that's 5 scenarios - the one where mandatory data ismissing, the one with no flights,the one where the flight with too few seats is filtered out,the one with 1 adult by default, and the one with 2 adults.

(我把测试人员放在那里是因为他们非常擅长发现其他人没有想到的场景。)

因此,在讨论了系统应该做什么之后,我们现在有了一些不同的场景。

场景发生的上下文——所有事先创建的——是“给定的”。发生的 Action (提交航类搜索)是“时间”。产生的结果是“Thens”。您可以在“给定”中包含 URL 的设置 - 如果可以,请尝试使用业务语言而不是 API 语言来表达。

我也喜欢把事情具体化(提供目的地、出发日期和机场的例子),因为这有助于我们思考其他场景。

所以对于“强制数据丢失”的情况,我会有类似的东西:

Given a search for a flight on 17 Sep 2028 from LHR
When the search is submitted
Then the submitter should be told that the request could not be processed
And the text should contain "missing destination airport"

我不会为每个缺失的字段创建端到端的场景;在系统级别有一个就足够了。将其余的放在单元测试中(参见 Testing Pyramid ;避免测试冰淇淋甜筒)。写完它们后,获取反馈,看看您是否理解正确。

您的帖子缺少有关成功提交后会发生什么的信息;我在这里做了很多假设!我可能会把成功的提交和不成功的提交归为一组,除非数量太多导致混淆,然后将它们分开。

当然,您可能只是在测试验证/反腐败层!但是,如果您这样做,只需在单元测试中执行即可 - 您不需要 BDD 工具。

关于bdd - 无强制参数场景API测试,响应为错误码和消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66437560/

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