bdd风格rest api测试工具
behave-rest的Python项目详细描述
bdd风格的rest api测试工具
它使用python的requests来执行http请求,对大多数断言使用nose,对json验证使用trafaret,对bdd风格的测试使用behave。
安装
克隆project
运行
pip install -r requirements.txt # install required dependencies
或
运行
pip install behave_rest
运行
# to execute all feature files (all tests) behave # to execture specific feature behave features/twitter.feature # to see printed output add --no-capture behave --no-capture # run features with specific tags behave --tags=without_login --tags=slow
关于behave tool的更多信息,您可以在这里阅读https://pythonhosted.org/behave/index.html
测试示例
Feature: Twitter search Background: Setup environment Given I set base URL to "https://api.twitter.com/1.1/search" And I set "Authorization" header to "context.twitter_auth" Scenario: Search for tweets When I make a GET request to "tweets.json" with parameters |q| |stanfy| Then the response status code should equal 200 And the response structure should equal "twitterSearchData" And the response header "status" should equal "200 OK"
您可以从project repo
CI报告
behave支持JUnit报表,这些报表很容易被CI工具解析
要启用JUnit报表,请创建behave.ini文件:
[behave] junit=true
报告生成到/reports文件夹中
要添加到behave.ini中的另一个有用选项是:
stdout_capture=false将打印输出添加到报表中
显示计时=否隐藏每个步骤的计时
项目结构
功能文件旨在位于/features文件夹中
相应步骤位于/features/steps
项目总体结构如下:
+-- features/ +-- conf.yaml // store project config (urls, global variables, etc.) +-- environment.py // context setup steps (e.g. load from config) +-- *.feature // feature files +-- steps/ +-- __init__.py // used to import predefined steps +-- json_responses.py // response structures described in Trafaret format +-- *.py // steps related to corresponding feature (e.g. "login.py" contains steps that are related to "login.feature")