CNode

求推荐Node.js 中为 Restful API 编写单元测试的例子

问答
Wwang-weifeng发布于10 年前最后回复10 年前7 回复4753 浏览0 收藏

Node.js 中为 Restful API 编写单元测试

有没有好的这方面的例子求推荐,谢谢

查看回复

回复 (7)

S
stonephp#1·10 年前

用这个库包。 restspec 具体的写法参考这个。绝对简单 https://github.com/open-node/open-rest-es6-boilerplate

有问题随时问我。

S
stonephp#4·10 年前
引用 rwing@stonephp 额 有其他的吗 相对比对比

@rwing 其他的你搜索测试相关的东西应该能找到很多,写起来都比我这个复杂很多。

Q
qxl1231#5·10 年前

for example:

/* jslint node: true */
'user strict';
var chai = require('chai');
var app = require('../server');
var request = require('supertest');

chai.should();

var postData = {
  appId: 1,
  stamp: 20151010172847,
  userId: 11078,
  proType: 1,
  data: '',
  sign: 1
};

describe("测试Base2Pro类的接口", function() {

  describe("#/v1/base2pro/data/transmit", function() {

    describe("天气推送 —— checkWeatherPush", function () {
      it("正常参数输入时,返回码为200", function(done) {
        request(app)
          .post('/v1/base2pro/data/transmit?lat=40.227932&lon=116.160439&handleType=CheckWeatherPush')
          .send(postData)
          .expect(200, done);
      });
    });

    describe("水电量 —— getWasherCost", function () {
      it("正常参数输入时,返回码为200", function(done) {
        request(app)
          .post('/v1/base2pro/data/transmit?handleType=GetWasherCost&time=20151023&applianceId=17592195755496&resultType=2&expendType=1')
          .send(postData)
          .expect(200, done);
      });
    });

  });

});

W
wang-weifeng#6·10 年前
引用 qxl1231for example:

@qxl1231 谢谢

D
dfsq1311#7·10 年前

https://github.com/avajs/ava

import test from 'ava';

test(t => {
    t.deepEqual([1, 2], [1, 2]);
});
参与回复
登录后即可参与回复。登录