我们可以编写场景'在行为没有'给予'并直接从'当' ?
更多说明:
'背景' section已经处于测试场景所需的状态。 因此,我只想直接开始'当'并执行一些操作。
答案 0 :(得分:2)
简单地说,是的。如本例所示:
Feature: Testing Feature Without Given
Scenario: No given step
When we have no given step
Then our test should still work
# coding: utf-8
from behave import *
@when("we have no given step")
def step_impl(context):
pass
@then("our test should still work")
def step_impl(context):
pass
Feature: Testing Feature Without Given # test.feature:1
Scenario: No given step # test.feature:3
When we have no given step # steps\step.py:5
Then our test should still work # steps\step.py:10
1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
2 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.002s
但是,这可能不是最好的做法。测试用例意味着条件和预期结果。背景并不是要涵盖这种情况,而是更广泛的前提条件,例如环境设置或明显的步骤,例如打开浏览器来测试Web应用程序。