【问题标题】:How to avoid name conflicts in BDD (lettuce)如何避免 BDD(生菜)中的名称冲突
【发布时间】:2012-08-15 08:19:27
【问题描述】:

我正在用生菜在 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

【问题讨论】:

    标签: namespaces bdd lettuce


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-21
      • 2011-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-02
      • 1970-01-01
      相关资源
      最近更新 更多