Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger Codegen JMeter Test data template

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?

like image 347
Sumit Maingi Avatar asked Sep 14 '16 04:09

Sumit Maingi


1 Answers

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

like image 55
Richard Friedman Avatar answered Nov 09 '22 22:11

Richard Friedman