Git Product home page Git Product logo

swagger-testing's Introduction

Swagger Testing

Build Status

Automated RESTful API Testing Using SwaggerAPI

Note: This project is under development and is not ready yet.

Installation

npm install swagger-testing

Usage

Independent

var SwaggerTesting = require('swagger-testing');
var swaggerSpec = require('./swagger.json');

var swagger = new SwaggerTesting(swaggerSpec);

swagger.testOperation({path: '/pet', operation: 'GET'}, function (err) {
  if (!err) {
    console.log('Successfully tested GET /pet');
  }
});

swagger.testCRUD('/user', '/pet', function (err) {
  if (!err) {
    console.log('All CRUD operations for all objects in my API are tested successfully.');
  }
});

In Mocha/Jasmine tests

Use SwaggerTesting in your Mocha tests:

var SwaggerTesting = require('swagger-testing');
var swaggerSpec = require('./swagger.json');

var swagger = new SwaggerTesting(swaggerSpec);

// Automatically test all models
describe('My API', function() {
  it ('tests all objects CRUD operations', function(done){
    swagger.testCRUD('/user', '/pet', done);
  });
});

API

// Automatically test all models
swagger.testCRUD('/user', '/pet');
// Automatically test CRUD resources
swagger.testCRUD('/user');
// Test all non mutating paths
swagger.testAllOperations('GET');
// Test a specific operation
swagger.testOperation({
  path: '/pet',
  operation: 'PUT',
  data: pet
});

A complex flow

describe('CRUD Pet (Manual)', function() {
  var pet = null;

  it('Creates a Pet object', function(done) {
    swagger.testOperation({path: '/pet', operation: 'POST'}, function(err, result) {
      pet = result;
      done();
    });
  });

  it('Reads the created Pet object', function(done) {
    swagger.testOperation({path: '/pet/' + pet.id, operation: 'GET'}, done);
  });

  it('Updates the created Pet object', function(done) {
    pet.name = Math.random().toString(36);

    swagger.testOperation({
      path: '/pet',
      operation: 'PUT',
      data: pet
    }, done);
  });

  it('Deletes the created Pet object', function(done) {
    swagger.testOperation({path: '/pet/' + pet.id, operation: 'DELETE'}, done);
  });
});

Development

To make a new build

npm run build

To run the test

npm test

License

MIT

swagger-testing's People

Contributors

mohsen1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.