【问题标题】:Parameterize behave feature, pytest-style参数化行为特征,pytest 风格
【发布时间】:2018-04-05 15:59:57
【问题描述】:

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

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

实际参数本身也在运行时动态发现,通过一组动态确定的参数集运行所有测试。

【问题讨论】:

    标签: python bdd python-behave


    【解决方案1】:

    几乎所有 Gherkin 语法 BDD 工具(如 Behave、Cucumber 等)都支持一种称为“场景大纲”的东西,它应该可以满足您的需求。 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)
    

    很简单!

    【讨论】:

    • 啊,这很好......我意识到我从原始问题中省略了一件事,参数是在运行时动态确定的。这种方法可以支持吗?能否以某种方式动态生成功能/场景?
    • 你能给我一个这些参数的例子吗?
    • 当您想要一步生成多值夹具时,请求的功能也会很有帮助。这样,您就不需要重写和维护所有参数作为每个想要使用它们的测试的示例。
    猜你喜欢
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 2022-12-08
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多