Unit testing and Integration testing

General Tech QA/Testing 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on QA/Testing related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

i'm currently developping a nodejs/express rest api (personal project), and i wanted to learn as much as i ca from this project.

So in my project i'm using sequelize as an ORM layer, i have a model named `bus, and i have build CRUD endpoint to this model.

now i want to do some test this model/api i have developped, i read some tutorial about testing and found that there are multiple type of testing seperated in two big categories : white-box vs black-box.

So i have written some integration tests that test my api(integration test are black-box testing)

and i want right know to write some unit-testing, but i don't know what to test, the bus model is a Sequelize model, so everything that i would test would be already tested in the sequelize library it self. and testing the api endpoints is done via integration tests.

PS: its my first time writing tests.

i'm using the following technologies : nodejssequelizeexpressmochachai.

Bus Model Definition

const Sequelize = require('sequelize');

module.exports = function(sequelize) {

    let Bus =  sequelize.define('bus', {
        name: {
            type: Sequelize.STRING,
        },
    });


    Bus.associate = function(models) {
        Bus.hasOne(models.LaneBus, {
            foreignKey: 'busId'
        });
    };

    return Bus;
} 

Bus Api endpoint testings

const request = require('superagent');
const expect = require('chai').expect;

const app = require('../../src/app');
var http = require('http');

const models = require('../../src/models');


describe("bus", function () {

    var bus_id;

    it('should create bus', function (done) {

        request.post('http://localhost:3000/bus')
            .type('form')
            .send({
                name: 'bus_test_1',
            }).set('Accept', 'application/json')
            .set('Authorization', global.JWT_TOKEN_TEST_ADMIN)
            .end((err, res) => {
                expect(res.status).to.be.eq(201, 'invalid return code');
                expect(res.body.status).to.be.eq('success', 'invalid retun status');

                bus_id = res
                                                
                                                
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.