Mic*_*mza 4 python bdd python-behave
我正在寻找重复运行行为功能测试,但每个测试都有不同的参数,有点像 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,或者还有其他选择吗?
实际参数本身也在运行时动态找到,在一组动态确定的参数集上运行所有测试。
几乎所有 Gherkin 语法 BDD 工具(例如 Behave、Cucumber 等)都支持名为“场景大纲”的东西,它应该可以满足您的需求。从这些例子来看:
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 |
Run Code Online (Sandbox Code Playgroud)
并实施以下步骤:
@given('I put "{thing}" in a blender')
def step_given_put_thing_into_blender(context, thing):
context.blender = Blender()
context.blender.add(thing)
Run Code Online (Sandbox Code Playgroud)
很简单!
| 归档时间: |
|
| 查看次数: |
2327 次 |
| 最近记录: |