7

I am generating Jmeter's jmx file from a swagger definition, the JMX and test data CSV that gets generated seems pretty useless, it has no parameter information as to what the API expected, no http status code to response mapping information etc.

You can take any definition file, to reproduce this:

  1. go to http://editor.swagger.io/#/
  2. open any example from the file menu
  3. From the generate client menu, click on Jmeter

What I expected was a JMX with the entire skeleton of the API so that the QA people don't have to worry about that and focus only on tests.

All the clients that I produce for other languages/tools are good enough to go except Jmeter, am I doing anything wrong here?

Sumit Maingi
  • 2,173
  • 3
  • 24
  • 44

1 Answers1

10

I generated JMeter (JMX) for different APIs and I got it to work, though a few issues and caveats.

First it generates

  • User Defined Variables to substitute in Host, Port, testCases, csvFileName
  • a JMX per API
  • a Thread Group per Method (POST, GET, .. )
  • a HTTP Header Manager per thread group, blank but useful to be in there.
  • HTTP Sampler for each request
  • Loading of CSV Data for filling parameter values
  • HTTP Status Assertion which is validated on error code defined in CSV file

Caveats and Issues

  • It does not keep your host from config, it replaces with local host. You must change it or pass it in via command line
  • It uses a default port of 8080, this caused me some grief as well.
  • The loop count is controlled by variable, testCases. However there is a bug in swagger-code-gen template for JMeter if you want to pass this in via the command line

    • testCases variable has a bug in the template it defines testCases as ${__P(host,10)} but it should be ${__P(testCases,10)} enter image description here
  • GET Parameters are fill with 0 instead of ${variable_name}, this is from the template in swagger codegen. I have a fix in my fork that I have tested. The other option is just to fix it in the JMX file Original enter image description here And after editing Parameters enter image description here

Example Swagger that works

The following is the Swagger file I used (modified from echo) and the generated (with modification for Parameters) JMX. I have tested this JMX using RedLine13 Example Test and passing the parameters as required. Passing in parameters

-JtestCases=50 
-Jhost=mazimi-prod.apigee.net 
-Jport=80

And here is the example Yaml

---
swagger: '2.0'
info:
  version: 1.0.0
  title: Echo
  description: |
    #### Echos back every URL, method, parameter and header
    Feel free to make a path or an operation and use **Try Operation** to test it. The echo server will
    render back everything.
schemes:
  - http
host: mazimi-prod.apigee.net
basePath: /echo
paths:
  /{id}:
    get:
      parameters:
        - name: id
          in: path
          description: ID
          type: string
          required: true
        - name: user
          in: query
          description: name
          type: string
          required: true
        - name: location
          in: query
          description: location
          type: string
          required: true
      responses:
        200:
          description: Echo GET

Updated JMEter template in Swagger CodeGen

Since there are a few issues for making this work seamless within SwaggerCode Gen i created an issue and pull request. If you need to use it sooner the fork is over here https://github.com/richardfriedman/swagger-codegen/commit/5aff601eaccf67ec44bb681816d40a25e5aa20a3

Richard Friedman
  • 932
  • 7
  • 11
  • Thanks.. will look into it and come back soon – Sumit Maingi Sep 15 '16 at 01:40
  • ok i tried it... I took your branch and built it... generated the code.. it does look better... to put things into context.. I expected the body params to be pre-filled with the model schema for each api... was that unreasonable? The schemas are pretty big and nested and I hope to have the QA people not making spelling mistakes while sending the requests... can that be done somehow? – Sumit Maingi Sep 15 '16 at 07:51
  • I think this template can use quite a bit of improvements, and yes anything defined in the schema can make its way into the template. – Richard Friedman Sep 15 '16 at 12:49
  • ok, thanks for all your efforts @richard, I am going to leave the question open in case there is another tool apart from swagger-codegen that can do this better that I don't know about. – Sumit Maingi Sep 15 '16 at 23:12