以及前指定我的问题,我想告诉大家,我是新来测试领域,所以这里是我的问题:测试涉及数据库
我开发利用快递+ sequelize(MySQL的)一个REST API,我想为我的api写一些测试。我选择使用茉莉花库进行测试。
所以我知道我想测试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
@ HSchmale谢谢你的提议,但我想学习如何在通用测试中,所以我需要解决这个问题。 – karim