Setting up load testing with Artillery.io

I recently started writing load testing tests using the artillery tool. I used to write tests for K6, so I'll talk about the advantages of artillery over K6, and also write a step-by-step script to set up a project from scratch.





Step 1. Installation

npm install -g artillery@latest
      
      



Since we need not only to track the metrics, but also to make sure that the server sends the correct answer, we also install a plugin to compare the expected result with the received one:





npm i artillery-plugin-expect
      
      



Step 2. Create config

Target url, environment

The load testing configuration file is all we need to do to run the tests:





config:
  target: "https://yourapp.com/api"
      
      



environment , target url:





config:
  target: "https://bestapp.com/api"
  environments:
    dev:
      target: "https://bestapp.dev.com/api"
    qa:
      target: "https://bestapp.qa.com/api"
      
      



artillery . : duration – ; arrivalRate – , ; ramptTo – ; name - .





phases:
    - duration: 30
      arrivalRate: 1
      rampTo: 20
      name: test1
      
      



target url, , environment, .





:





plugins:
    expect: {}
      
      



username password:





- get:
    url: "/auth"
    auth:
      user: username
      pass: password
      
      



header:





- post:
    url: "/auth"
    headers:
      Authorization: β€œBasic secretKey”
      
      



3.

scenarios. , (GET, POST, PUT, DELETE .), url endpoint, body json, .





:





scenarios:
    - name: "My first test"
       flow:
         - post:
            url: "/endpoint1"
            json:
              id: value
        expect: 
          - statusCode: 200
          - contentType: json 
          - equals: 
             - respMessage: "OK"
      
      



equals , .





4.

:





artillery run yourConfig.yml
      
      



scripts package.json .





-e <env> - environment,

--quiet – ,

-o result.json – .





html

:





artillery report result.json
      
      



K6

The main advantage of artillery is that it is very easy to set up the first test run. No need to rewrite tests in the format defined for K6, no need to write a bat-file in order to run multiple tests and save the results to a separate folder. It is enough to configure one file.





Artillery works with node.js, so the startup script can be inserted into package.json.





You can import variables from a cvs file, take variables from the result.





The report with graphs and charts is added in one command and is included in the free version of artillery.








All Articles