samedi 17 juin 2017

Testing Involving Database

well before specifying my problem, i want to tell that i'm new to the field of testing, so here is my problem:

i developed a rest api using express + sequelize(mysql), and i want to write some test for my api. i choosed to use jasmine library for testing.

so right know i want to test the create and update rest endpoint, i will need access to a database, but the problem is that the test cases are run in parallel, and there is only one database, so if i want to delete all item from a table in a test case, and another test case have create a row in that table, there will be a problem.

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);
            }


        });

    });



});

Aucun commentaire:

Enregistrer un commentaire