python behave框架做接口测试原理

1、behave简介

behave 是一种行为驱动开发的模式,python安装: pip install behave

behave官方文档教程:Tutorial — behave 1.2.7.dev2 documentationicon-default.png?t=L892https://behave.readthedocs.io/en/latest/tutorial.html

2、 behave文件结构

#最简单的文件结构

features/
features/everything.feature  #case文件
features/steps/ 
features/steps/steps.py #包含python步骤实现的函数,一些关键字的实现
除以上文件结构,开发者可根据需要新建目录或者文件编写函数实现需求。

#文件内容示例

#1、feature文件示例
Feature: test1111

#有时,一个场景应该与多个变量一起运行,给出一组已知状态、要采取的行动和预期结果,所有这些都使用相同的基本行动
Scenario 1: 场景名称1
   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        |

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

Scenario 2: 场景名称2
    # * 符号代表given
   * 请求"POST"接口"xxx/xxxx"
    '''
    {.....}
    '''

#2、steps.py 步骤实现示例
from behave import *

@given(u'请求"(?P<method>.*)"接口"(?P<api>.*)"')
def send_request(context, method, api):
    xxxxx 

@when('we implement a test')
def step_impl(context):
    assert True is not False

@then('behave will test it for us!')
def step_impl(context):
    assert context.failed is False


#3、context的使用
全局?保存变量?取值?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值