Skip to content

apigee-127/swagger-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swagger Testing

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

About

Automated API Testing Using SwaggerAPI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published