码迷,mamicode.com
首页 > Web开发 > 详细

frisby.js-接口测试基础知识

时间:2017-01-21 14:01:54      阅读:415      评论:0      收藏:0      [点我收藏+]

标签:响应   objects   node   unit   精确   ber   comment   mil   help   

一、安装环境

1.先更新yum语言

curl -sL https://rpm.nodesource.com/setup | bash -

2.安装nodejs yum install -y nodejs

3.jasmine
npm install -g jasmine-node

4.frisby
npm install--save-dev frisby

 

二、运行脚本 test_spec.js

jasmine-node  test_spec.js

 

三、生成XML报告

jasmine-node test_spec.js --junitreport

四、常用的Expectations

 

1.expectStatus( code )   响应返回的HTTP状态码等于code

2.expectHeader( key, content )  期望的头信息  精确的

例如:

frisby.create(‘Ensure response has a proper JSON Content-Type header‘)
  .get(‘http://httpbin.org/get‘)
  .expectHeader(‘Content-Type‘, ‘application/json‘)
.toss();
3.expectHeaderContains( key, content ) 期望的头信息   不精确的

例如:

frisby.create(‘Ensure response has a proper JSON Content-Type header‘)
  .get(‘http://httpbin.org/get‘)
  .expectHeader(‘Content-Type‘, ‘json‘)
.toss();
4.expectHeaderToMatch( key, patterm )  期望的头信息,使用正则表达式匹配的
例如:
frisby.create(‘Ensure response has image/something in the Content-Type header‘)
  .get(‘http://httpbin.org/get‘)
  .expectHeaderToMatch(‘Content-Type‘, ‘^image/.+‘)
.toss();

5.expectJSON( [path], json )  期望的JSON 

例如:

frisby.create(‘Ensure test has foo and bar‘)
  .get(‘http://httpbin.org/get?foo=bar&bar=baz‘)
  .expectJSON({
    args: {
      foo: ‘bar‘,
      bar: ‘baz‘
    }
  })
.toss()

6.expectJSONTypes( [path], json )  期望json的类型

例如:

frisby.create(‘Ensure response has proper JSON types in specified keys‘)
  .post(‘http://httpbin.org/post‘, {
    arr: [1, 2, 3, 4],
    foo: "bar",
    bar: "baz",
    answer: 42
  })
  .expectJSONTypes(‘args‘, {
    arr: Array,
    foo: String,
    bar: String,
    answer: Number
  })
.toss()
7.expectBodyContains( content )  body内容
8.expectJSONLength( [path], length )  JSON长度
9.expectMaxResponseTime( milliseconds )  最大响应时间
 
五、path
1.All Objects in an Array
所有的对象都在一个数组内,可用 * 作为path
2.One Object in an Array
一个对象在一个数组内,可以用 ? 作为path
 
六、Helpers

1.after()

frisby.create(‘First test‘)
  .get(‘http://httpbin.org/get?foo=bar‘)
  .after(function(err, res, body) {
 
    frisby.create(‘Second test, run after first is completed‘)
      .get(‘http://httpbin.org/get?bar=baz‘)
    .toss()
 
  })
.toss()
2.afterJSON()  返回的JSON在别的里面使用
frisby.create(‘First test‘)
  .get(‘http://httpbin.org/get?foo=bar‘)
  .afterJSON(function(json) {
 
  // Now you can use ‘json‘ in additional requests
    frisby.create(‘Second test, run after first is completed‘)
      .get(‘http://httpbin.org/get?bar=‘ + json.args.foo)
    .toss()
 
  })
.toss()
3.inspectRequest()  发送的请求
 
详细学习地址:http://frisbyjs.com/docs/api/


 

frisby.js-接口测试基础知识

标签:响应   objects   node   unit   精确   ber   comment   mil   help   

原文地址:http://www.cnblogs.com/minna/p/6336917.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!