zoukankan      html  css  js  c++  java
  • 十、collection的作用+变量

    一、collection作用?容器

    • 组织业务逻辑
    • 导入导出
    • 其他功能,比如监控和mock server

    二、为什么要使用变量

    假设我们需要测试n个api,这些api的domain都是相同的,比如

    • api.itest.info/tasks
    • api.itest.info/tasks/:task_id

    如果有一天,api的domain变化了,不再是api.itest.info,那么就麻烦了

    • {{itest_domain}}/tasks
    • {{itest_domain}}/tasks/:task_id

    三、postman变量作用域

    • Global:全局,比如可以将错误提示信息设置成全局变量
    • Environment:环境变量,比如可以在sandbox中定义
    • Local:本地变量,一般可以在sandbox中定义
    • Data:测试数据中导入的变量,也就是所谓的参数化

    四、变量的引用

    我们可以在builder里引用变量

    {{variable}}

    五、管理环境变量和全局变量

    演示

    https://www.v2ex.com/api/nodes/show.json?name=python

    node_name:php/python/qna

    六、运行collection

    演示

    如何创建json格式的data

    如何在postman中运行

    七、为什么要在命令行中运行

    • 可以在无ui界面的服务器上运行
    • 可以在ci持续集成系统上运行

    1、运行准备

    • 导出collection
    • 安装nodejs和npm
    • 安装newman

    2、运行及生成测试报告

    • CLI reporter
    • JSON reporter
    • HTML reporter
    • JUnit reporter

    演示:生成html报告

    https://postman-echo.com/get?test=123

    try{
        responseJSON =JSON.parse(responseBody);
        tests['response is valid JSON']  = true;
    }
    catch (e) {
        responseJSON = {};
        tests['responser is valid JSON'] = false;
    }
    tests['response json contains headers'] = _.has(responseJSON,'headers');
    tests['response json contains args'] = _.has(responseJSON,'args');
    tests['response json contains url'] = _.has(responseJSON,'url');
    tests['args key contains argument passed as url parameter'] = ('test' in responseJSON.args);

  • 相关阅读:
    安装Hadoop单机版
    Linux的en33没有IP地址
    idea导入spring源码
    CSS 选择器之基础选择器
    CSS 简介和代码风格
    JavaScript 中 双感叹号 !! 的作用
    VS Code 中的settings.js 配置
    项目中使用 vuex 实现(状态)数据共享
    VS Code 相关设置
    Node.js 的简单了解
  • 原文地址:https://www.cnblogs.com/xinxin1994/p/11259283.html
Copyright © 2011-2022 走看看