我正在尝试重用在先前运行的方案期间创建的值。 我不确定黄瓜是否有办法在各种情景中提供价值。 例如:
第一种情况:
给定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.
更多推荐
发布评论