下面来创建一个基本的行为测试。
特征文件
假设有一个名为“付款类型(Payment Types)”的特征文件如下 -
Feature − Payment Types
Scenario − Verify user has two payment options
Given User is on Payment screen
When User clicks on Payment types
Then User should get Types Cheque and Cash
对应步骤实现文件
上述特征的相应步骤实现文件如下 -
from behave import *
@given('User is on Payment screen')
def impl_bkpy(context):
print('User is on Payment screen')
@when('User clicks on Payment types')
def impl_bkpy(context):
print('User clicks on Payment types')
@then('User should get Types Cheque and Cash')
def impl_bkpy(context):
print('User should get Types Cheque and Cash')
项目结构
“付款类型(Payment Types)”特征的项目结构如下 -
运行特征文件后得到的输出如下所述,这里使用的命令是behave
-
输出显示功能和场景名称,以及测试结果和测试执行的持续时间。
Python控制台输出如下 -