来自先前运行场景的黄瓜重用值(Cucumber reuse value from previously run scenario)

编程入门 行业动态 更新时间:2024-10-28 21:30:25
来自先前运行场景的黄瓜重用值(Cucumber reuse value from previously run scenario)

我正在尝试重用在先前运行的方案期间创建的值。 我不确定黄瓜是否有办法在各种情景中提供价值。 例如:

第一种情况:

给定inputOfA

创建A时

然后返回A.

并且A包含Id

第二种情景:

鉴于IdOfA

当客户通过Id获得A时

然后返回A.

对于第二种情况,如果我可以从第一个创建Id而不必将其保留在任何地方,那将会很棒。 你们中的任何人都可以通过黄瓜告诉我这是否可能,或者我是否必须坚持在第一个场景中创建的Id?

I am trying to reuse a value that was created during the previously run scenario. I am not sure if there is a way in cucumber to make a value available across scenarios. For instance:

1st scenario:

Given inputOfA

When A is created

Then A is returned

And A contains an Id

2nd Scenario:

Given IdOfA

When customer gets A by Id

Then A is returned.

For the 2nd scenario, it would be great if I can get the Id created from the first without having to persist it anywhere. Can any of you let me know if this is possible using cucumber or do I have to persist the Id created in the first scenario?

最满意答案

这不是你想要的。

它需要以特定顺序执行方案。 未指定方案执行顺序。 它甚至可能是随机的。

您想要的独立场景。 您可以按任何顺序执行的方案。

如果要在将来的方案中使用来自一个方案的结果,则需要设置第二个方案以执行与上一个方案应该完成的操作相同的操作。 这可能感觉像是重复,也许是重复。 但是BDD的使用是为了推动实施。 第一个场景用于驱动某些行为。 第二种情况应该用于驱动另一种行为。

当第二个场景实现时,可能会删除第一个场景。 如果是多余的,请将其删除。

但无论你做什么,都要避免相互依赖的场景。 它只会导致一个看似随机错误的坏地方。

This is not something you want.

It would require the scenarios to be executed in a specific order. The scenario execution order isn't specified. It may even be random.

What you want scenarios that are independent. Scenarios you can execute in any order.

If you want to use the result from one scenario in a future scenario, you want to setup the second scenario to execute the same thing as the previous scenario should have done. This may feel like duplication and maybe it is. But the usage of BDD is to drive the implementation. The first scenario was used to drive some behaviour. The second scenario should be used to drive another behaviour.

It is possible that the first scenario can be deleted when the second is implemented. If it is redundant, remove it.

But whatever you do, avoid the path of scenarios that depends on each other. It will only lead to a bad place with seemingly random errors occurring.

更多推荐

本文发布于:2023-08-06 11:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448595.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:黄瓜   先前   场景   Cucumber   scenario

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!