参数化行为特征,pytest 风格

Parameterize behave feature, pytest-style

我正在寻找 运行 反复进行特性测试,但每个都有不同的参数,有点像 pytest 的参数化 https://docs.pytest.org/en/latest/reference.html#pytest-mark-parametrize-ref

我找不到任何表明这可以在单个 运行 行为中完成的信息。这是否必须在外部完成,例如通过一个 bash 脚本,该脚本多次调用,每个 运行 都有使用例如用户数据 http://behave.readthedocs.io/en/latest/behave.html?highlight=userdata#cmdoption-define 传递的参数,或者是否有替代方法?

实际参数本身也在 运行 时动态找到,运行对一组动态确定的参数集进行所有测试。

几乎所有 Gherkin-syntax BDD 工具(例如 Behave、Cucumber 等)都支持一种名为 "Scenario Outline" 的东西,它应该可以满足您的需求。 From these examples here:

Feature: Scenario Outline (tutorial04)

  Scenario Outline: Use Blender with <thing>
    Given I put "<thing>" in a blender
    When I switch the blender on
    Then it should transform into "<other thing>"

    Examples: Amphibians
        | thing         | other thing |
        | Red Tree Frog | mush        |
        | apples        | apple juice |

    Examples: Consumer Electronics
        | thing         | other thing |
        | iPhone        | toxic waste |
        | Galaxy Nexus  | toxic waste |

并实施步骤:

@given('I put "{thing}" in a blender')
def step_given_put_thing_into_blender(context, thing):
    context.blender = Blender()
    context.blender.add(thing)

很简单!