【发布时间】:2017-06-17 14:33:35
【问题描述】:
在说明我的问题之前,我想告诉你我是测试领域的新手,所以这是我的问题:
我使用 express + sequelize(mysql) 开发了一个 rest api,我想为我的 api 编写一些测试。我选择使用 jasmine 库进行测试。
所以知道我想测试create 和update 休息端点,我需要访问一个数据库,但问题是测试用例是并行运行的,并且只有一个数据库,所以如果我想从测试用例的表中删除所有项目,而另一个测试用例在该表中创建了一行,则会出现问题。
const request = require('superagent');
const models = require('../../src/models');
const Station = models.Station;
describe("station testing", function () {
before(() => {
// delete and recreate all database table
// before running any test
});
describe("crud station", function () {
it('should create model', () => {
Station.create({
'name': 'test',
lat: 12,
long: 123,
}).then( model => {
expect(model).toBeTruthy();
});
});
it('should delete evrything', () => {
Station.deleteAll().then( () => {
// problem here if after the first model is created and before create model except is executed
expect(Station.Count()).toEqual(0);
}
});
});
});
【问题讨论】:
-
另一个可能更适合您的测试框架是 pyresttest。您只需定义您期望的请求和响应的样子,然后它就可以检查它。
-
@HSchmale 感谢您的提议,但我想学习如何进行一般测试,所以无论如何我都需要解决这个问题。
标签: node.js unit-testing express testing jasmine