Skip to content

API automation testing framework built on Mocha with Supertest that makes testing API endpoints easy, fast, and fun

License

Notifications You must be signed in to change notification settings

reddysuren/supertest-mocha-framework

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

supertest-mocha-framework

About

supertest-mocha-framework is a open source api testing framework built on mocha and supertest to make the api testing simple, easy and fun. We continuously working on framework to provide you a seamless experience by adding more and more commandline options and features.

Changelog:

  • All notable changes can be found here

Getting Started

Usage

  • Run npm i --save supertestmocha
  • mocha and supertest are peer dependencies, you can install explicitly.

Configure

  • Create a confuguration object containing BaseUrl of your apis endpoints or application
var  config = {
	"baseUrl": "https://reqres.in",
	"debug": true | false
}
  • Require the supertestmocha in your test file or global config file
var  supermocha = require('supertestmocha')
var  test = new  supermocha(config);

Creating Test Cases

  • Use the test object to create test cases
  • Pass the options object to test object
  • Response can be handled in Callback function
var expect = require('chai').expect;

describe('Test Suite...', function () {
    this.timeout(18000)

    // Example Test Case 01
    it('\n1. Create a Test User', function (done) {
        test({
            uri: '/api/users',
            method: 'post',
            json: {
                "name": "Test User",
                "job": "Quality Check"
            }
        }, function (err, res) {
            test.assert(err, res, function () {
                expect(res.body).to.have.property('name', 'Test User')
                expect(res.body).to.have.property('job', 'Quality Check')
                // Add required assertion here
            }, done)
        })
    });
});

Params

test({options}, cb);
  • @param {object} options - an object that hold the uri, method, json, headers content-type etc..
  • @param {function} cb- callback function to handle response

Running Tests

  • Use mocha as runner: mocha example\use.js -[options]
  • Example command mocha example\use.js -d

Command Options

  • -d | --debug to debug the api, it will log the api request and reponse
  • -p | --parallel use to run the test cases in parallel
  • -l | --logs save the logs in .log file

About

API automation testing framework built on Mocha with Supertest that makes testing API endpoints easy, fast, and fun

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%