以及前指定我的問題,我想告訴大家,我是新來測試領域,所以這裏是我的問題:測試涉及數據庫
我開發利用快遞+ 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