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")

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java操作数组上的字符串   java JAXB内容未实例化   图形在Java中如何绘制垂直居中的字符串?   java Apache Ant:使用Junit时出现NoClassDefFoundError   java无法从服务器上运行perl脚本   如何在java中沿树进行预排序遍历,并打印0和1以对应每个节点上的特定字符?   java如何创建。p12文件?   java线程访问无效   java只匹配命名空间中的XML节点,而不知道NS前缀   从java获取2d arraylist元素   数组Java动态集合对象   java Xpath通过通配符或布尔运算查找以相同名称开头的节点?   java注释元素类型   java在中看不到Super()。反编译后的类文件