Generate test code from a Swagger spec(version 2.0)
Install via npm
npm install --save swagger-test-templates
Use your Swagger API spec file to generate test for your API.
var stt = require('swagger-test-templates');
var swagger = require('/path/to/swagger.json');
var config = {
assertionFormat: 'should',
testModule: 'supertest',
pathName: ['/user', '/user/{id}'],
loadTest: [{pathName:'/user', operation:'get', load:{requests: 1000, concurrent: 100}}, { /* ... */ }],
maxLen: 80
};
// Generates an array of JavaScript test files following specified configuration
stt.testGen(swagger, config);
swagger-test-templates
module exports a function with following arguments and return values:
assertionFormat
required: One ofshould
,expect
orassert
. Choose which assertion method should be used in output test code.testModule
required: One ofsupertest
orrequest
. Choose between direct API calls (request
) vs. programatic access to your API (supertest
).pathNames
required: List of path names available in your Swagger API spec used to generate tests for. Empty array leads to all paths.loadTest
optional: List of objects info in your Swagger API spec used to generate stress tests. If specify, pathName & operation are required. Optional fields requests defaults to1000
, concurrent defaults to100
.maxLen
optional: Maximum line length. Defaults to80
.
An array in which each string is content of a test file and the file name. Use this information to write those files to disk.
##License MIT