gpt4 book ai didi

namespaces - 如何避免 BDD 中的名称冲突(生菜)

转载 作者:行者123 更新时间:2023-12-04 16:58:08 24 4
gpt4 key购买 nike

我正在用生菜来学习 Django 中的 BDD,同时我想到了一种情况,即不同场景中的两个步骤碰巧具有相同的名称,例如,

Feature: a feature A
Scenario: a scenario S1
Given this is the conflicted step
Then chect the result of scenario S1

Feature: a feature B
Scenario: a scenario S2
Given this is the conflicted step
Then chect the result of scenario S2

以上步骤 这是冲突的步骤 碰巧在具有不同含义的多个场景中定义。然后,将针对此步骤的所有出现执行以下此步骤的测试代码。
@step(r'this is the conflicted step')
def mytest(step):
# do test

我的问题是,是否有一种命名空间机制允许我们为具有相同名称但在不同场景中的步骤创建不同的测试代码?例如,我希望有以下测试代码或类似的代码:
@step(r'a feature A', r'this is the conflicted step')
def aaaa(step):
# do test

@step(r'a feature B', r'this is the conflicted step')
def bbbb(step):
# do other test

最佳答案

我不熟悉生菜,但在 Cucumber 中,您有 Background 的概念。 .

使用 Background ,您可以为所有场景定义一个共享的“给定”步骤,因此您可以删除冲突的步骤。

如果这不是您所需要的,那么您将不得不更改步骤的文本,以更具体地说明它们的作用,以消除冲突。

关于namespaces - 如何避免 BDD 中的名称冲突(生菜),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11966052/

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