简体   繁体   English

行为(BDD)AmbiguousStep错误

[英]behave(BDD) AmbiguousStep Error

Starting play with Behave BDD test, I found there is no step definition namespace things, which can easily result in an AmbiguousStep exception.开始玩Behave BDD 测试,我发现没有步骤定义命名空间的东西,这很容易导致 AmbiguousStep 异常。 What are the best practises here?这里的最佳做法是什么? I think this will be a problem when your test project is getting bigger.我认为当您的测试项目越来越大时,这将是一个问题。

Here is what I'm trying to do:这是我想要做的:

feature-1:特征 1:

Feature: feature1
  Scenario: f1s1
    When take action
    Then it's ok

feature-2:特征 2:

Feature: feature1
  Scenario: f2s1
    When take action
    Then it's ok

foo4feature1.py: foo4feature1.py:

@when('take action')
def step_impl(context):
    assert True

@then("it's ok")
def step_impl(context):
    assert True

bar4feature2.py: bar4feature2.py:

@when('take action')
def step_impl(context):
    assert True # some other logic here according to feature2

my two features( feature-1 and feature-2 ) both have step take action .我的两个功能(功能 1功能 2 )都有 step take action These tow steps have different meaning from each other in their scenario.这两个步骤在它们的场景中具有不同的含义。 They just happen to be the same name(eg, take action ).他们只是碰巧同名(例如,采取行动)。 I know I can carefully pick the name of steps(eg, use "take action of f2" instead of "take action" in feature2 ) to avoid conflict.我知道我可以仔细选择步骤的名称(例如,在feature2 中使用“take action of f2”而不是“take action”)以避免冲突。 However in a big test project, you cannot ensure everybody remember the step names in everybody else's features.但是,在大型测试项目中,您无法确保每个人都记住其他人功能中的步骤名称。 As a newbie in the BDD things, I'm looking for best practises to follow to handle this problem.作为 BDD 方面的新手,我正在寻找可遵循的最佳实践来处理这个问题。

In general, you need to be concise with your steps (that is true for most BDD frameworks).通常,您的步骤需要简洁(对于大多数 BDD 框架都是如此)。 Therefore, the same step within one directory scope can only have one meaning.因此,同一目录范围内的同一步骤只能具有一种含义。 If you need two different meanings for the same step (text), you currently need to use different directories.如果你需要对同一个步骤(文本)有两种不同的含义,你目前需要使用不同的目录。

In the future, behave will provide a "feature specific" scope concept.将来,behave 将提供“特定于功能的”范围概念。 This will you allow you to exactly what you want.这将使您能够完全满足您的需求。

BDD is a communication and collaboration technique. BDD 是一种通信和协作技术。 Tools exist to directly automate the examples that the customer, developer and tester discover together, but the scenarios should be written in the 'ubiquitous language' of your domain (see the book Domain Driven Design by Eric Evans).存在直接自动化客户、开发人员和测试人员共同发现的示例的工具,但场景应该用您所在领域的“无处不在的语言”编写(请参阅 Eric Evans 所著的领域驱动设计一书)。

So, the short answer is that best practice requires the collaborative definition of a shared vocabulary.因此,简短的回答是最佳实践需要共享词汇表的协作定义。 The scenarios are then much easier to read and understand.... which is a good thing.然后这些场景更容易阅读和理解......这是一件好事。

Adding this to the environment.py fixed my issue.将此添加到 environment.py 解决了我的问题。 You need to import parse.您需要导入解析。

@parse.with_pattern(r'[^"]*')
def parse_unquoted(text):
  """Parse/match string(s) that do not contain double-quote characters."""
  return text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM