Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

How to use it #148

Open
spacemonkeyHere opened this issue Jul 11, 2017 · 2 comments
Open

How to use it #148

spacemonkeyHere opened this issue Jul 11, 2017 · 2 comments

Comments

@spacemonkeyHere
Copy link

Hi,
it may be a noob question but how do you use the example on this page ?
after installing this npm package and adding the example i just get a weird error
ode_modules/swagger-test-templates/templates/default/get/get.handlebars' at Error (native) at Object.fs.openSync (fs.js:640:18) at Object.fs.readFileSync (fs.js:508:33) at testGenResponse (

I am guessing you miss some noob tutorial ?
I also tried following
https://apigee.com/about/blog/developer/swagger-test-templates-test-your-apis
installing all the missing packages but still o do not see how this example is connected to what is in the article.
My question is how to i generate these api tests based on the specification of my swagger api with load testing ?

thank you

@baynezy
Copy link
Contributor

baynezy commented Jul 12, 2017

You can use it like so:-

var fs = require("fs"),
    stt = require("swagger-test-templates"),
    swagger = require("swagger.json"),
    config = {
        assertionFormat: "expect",
        testModule: "request",
        pathName: [],
        maxLen: -1
    };

var tests = stt.testGen(swagger, config);

tests.forEach(function(element) {
    fs.writeFile("./test/" + element.name, element.test, (err) => {
        if (err) throw err;

        console.log(element.name, " written");
    });
}, this);

This will parse your swagger.json and create several test files in a directory test. At this point you have a folder of tests that can be run with Mocha. So to run them navigate to test then run the following:-

npm install mocha
npm install chai
npm install request
npm install z-schema
npm install dotenv
mocha

I hope that helps.

@shadowman9443
Copy link

How to run this file
var fs = require("fs"),
stt = require("swagger-test-templates"),
swagger = require("swagger.json"),
config = {
assertionFormat: "expect",
testModule: "request",
pathName: [],
maxLen: -1
};

var tests = stt.testGen(swagger, config);

tests.forEach(function(element) {
fs.writeFile("./test/" + element.name, element.test, (err) => {
if (err) throw err;

    console.log(element.name, " written");
});

}, this);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants