项目作者: rkpareek

项目描述 :
API automation testing framework built on Mocha with Supertest that makes testing API endpoints easy, fast, and fun
高级语言: JavaScript
项目地址: git://github.com/rkpareek/supertest-mocha-framework.git
创建时间: 2020-10-18T07:28:18Z
项目社区:https://github.com/rkpareek/supertest-mocha-framework

开源协议:MIT License

下载


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

Contribution:

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. A demo project is also available in ./demo-project folder for the reference
  1. var config = {
  2. "baseUrl": "https://reqres.in",
  3. "debug": true | false
  4. }
  • Require the supertestmocha in your test file or global config file
  1. var supermocha = require('supertestmocha')
  2. var test = new supermocha(config);

Creating Test Cases

  • Use the test object to create test cases
  • Use test.assert to apply the chaijs assertion
  • Pass the options object to test object
  • Response can be handled in Callback function
  1. var expect = require('chai').expect;
  2. describe('Test Suite...', function () {
  3. this.timeout(18000)
  4. // Example Test Case 01
  5. it('\n1. Create a Test User', function (done) {
  6. test({
  7. uri: '/api/users',
  8. method: 'post',
  9. json: {
  10. "name": "Test User",
  11. "job": "Quality Check"
  12. }
  13. }, function (err, res) {
  14. test.assert(err, res, function () {
  15. expect(res.body).to.have.property('name', 'Test User')
  16. expect(res.body).to.have.property('job', 'Quality Check')
  17. // Add required assertion here
  18. }, done)
  19. })
  20. });
  21. });

Params

  1. 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