标签:
1 var config = require(‘../config/endpoints‘), 2 request = require(‘supertest‘)(config.host[config.env]); 3 4 5 describe(‘测试访问baidu首页.‘, function() { 6 it(‘返回状态码为200.‘, function(done) { 7 request.get(‘/‘) 8 .expect(200) 9 .end(done); 10 }); 11 12 });
? api-test git:(master) ? grunt Running "mochaTest:test" (mochaTest) task 测试访问baidu首页. ? 返回状态码为200. (958ms) 1 passing (964ms) Done, without errors.
1 var config = require(‘../config/endpoints‘), 2 request = require(‘supertest‘)(config.host[config.env]); 3 4 5 describe(‘测试访问baidu首页.‘, function() { 6 it(‘返回状态码为200.‘, function(done) { 7 request.get(‘/‘) 8 //此处失败 9 .expect(201) 10 .end(done); 11 }); 12 13 });
? api-test git:(master) ? grunt Running "mochaTest:test" (mochaTest) task 测试访问baidu首页. 1) 返回状态码为200. 0 passing (2s) 1 failing 1) 测试访问baidu首页. 返回状态码为200.: Error: expected 201 "Created", got 200 "OK" Warning: Task "mochaTest:test" failed. Use --force to continue. Aborted due to warnings.
request.get(‘/‘)
.set(‘Content-Type‘,‘application/json‘)
1 request 2 .post(‘/post/data‘) 3 .send({ 4 "A": 1, 5 "B": 2 6 })
.expect(function(res){ //返回中totalCount为6 if (!(res.body.totalCount.should.equal(6))) throw new Error("总数不对"); })
总结-测试规划
标签:
原文地址:http://www.cnblogs.com/s380774061/p/4814756.html