KEMBAR78
Gatling Performance Workshop | PDF
PERFORMANCE TESTING WITH
GATLING
Thoughtworks Bangalore
Overview
What is covered?
● Brief about Gatling
● Pre-requisites
● Writing first test - hands on
What is not covered?
● Performance load modelling
● Scala language itself
● Gradle - Build tool that we have used
What is Gatling?
Performance testing framework developed using Scala with a focus on web
applications
● Server side
● Written in Scala
Why Gatling?..
1. Open-source tool
2. Simple
3. High performance
4. Good reports
5. Easy integration with CI
Pre-requisites
1. Java
2. Scala
3. Any build tool (optional) - We will be using Gradle
4. Any IDE like Eclipse or IntelliJ
Machine set up
https://github.com/swetashegde/gatling-for-beginners has detailed steps
for Mac and Windows set up with a sample project.
Let’s begin..
Run a sample server to test
To run a local server on machines:
mb start --configfile=mb-config.ejs
Use postman to check the endpoints.
Create a Gradle Project
Create a Gradle Project
Edit your build.gradle file:
● Add dependencies
● Add task gatling
Create the Project Skeleton
Create the following structure for your project:
Some Keywords
val - constant value
object - class with a single instance
exec - execution step
http - declares an http request
scenario- declares a scenario
Find more : http://gatling.io/#/cheat-sheet/2.2.2
Setting up the protocol
This is where we set up:
● Base domain for our tests
Example: http://www.example.com/search
● Request headers that the target APIs accept
Example: Content-Type: application/json
Writing a simple query
A query can be constructed for each endpoint under test. Writing this way would
make the tests simpler and readable
Query consists of:
● Query name and request name
● Endpoint with request method
● Any specific params
● Expected response
Syntax:
val <name> = http(“<query_name>”)
.<request-method>(“/endpoint”)
.check(<expected_status>)
Scenarios
Scenarios are essentially user flows that we would want to simulate.
Usual way to construct a simple scenario is:
● Add queries in a sequential manner to create a user journey
● Add waits in between if required
Syntax:
val name = scenario(<scenario_name>)
.exec(query1)
.pause()
.exec(query2)
...
Simulations
Simulations are where we define the amount of load we want to inject into our
servers
Things required to construct a simulation:
● Scenario
● Protocol
● Assertions
Syntax:
setUp(<scenario>.inject(<injection_step>))
.protocols(<protocol_name>)
.assertions(<condition>)
Get..set..run!!
gradle clean gatling
REPORTS
References & credits
● http://gatling.io/
● https://github.com/lkishalmi/gradle-gatling-plugin
● http://www.mbtest.org/
● https://www.thoughtworks.com/insights/blog/gatling-take-your-performance-tests-next-level
● http://gatling.io/#/cheat-sheet/2.1.7
THANK YOU

Gatling Performance Workshop

  • 1.
  • 2.
    Overview What is covered? ●Brief about Gatling ● Pre-requisites ● Writing first test - hands on What is not covered? ● Performance load modelling ● Scala language itself ● Gradle - Build tool that we have used
  • 3.
    What is Gatling? Performancetesting framework developed using Scala with a focus on web applications ● Server side ● Written in Scala
  • 4.
    Why Gatling?.. 1. Open-sourcetool 2. Simple 3. High performance 4. Good reports 5. Easy integration with CI
  • 5.
    Pre-requisites 1. Java 2. Scala 3.Any build tool (optional) - We will be using Gradle 4. Any IDE like Eclipse or IntelliJ
  • 6.
    Machine set up https://github.com/swetashegde/gatling-for-beginnershas detailed steps for Mac and Windows set up with a sample project.
  • 7.
  • 8.
    Run a sampleserver to test To run a local server on machines: mb start --configfile=mb-config.ejs Use postman to check the endpoints.
  • 9.
  • 10.
    Create a GradleProject Edit your build.gradle file: ● Add dependencies ● Add task gatling
  • 11.
    Create the ProjectSkeleton Create the following structure for your project:
  • 12.
    Some Keywords val -constant value object - class with a single instance exec - execution step http - declares an http request scenario- declares a scenario Find more : http://gatling.io/#/cheat-sheet/2.2.2
  • 13.
    Setting up theprotocol This is where we set up: ● Base domain for our tests Example: http://www.example.com/search ● Request headers that the target APIs accept Example: Content-Type: application/json
  • 14.
    Writing a simplequery A query can be constructed for each endpoint under test. Writing this way would make the tests simpler and readable Query consists of: ● Query name and request name ● Endpoint with request method ● Any specific params ● Expected response Syntax: val <name> = http(“<query_name>”) .<request-method>(“/endpoint”) .check(<expected_status>)
  • 15.
    Scenarios Scenarios are essentiallyuser flows that we would want to simulate. Usual way to construct a simple scenario is: ● Add queries in a sequential manner to create a user journey ● Add waits in between if required Syntax: val name = scenario(<scenario_name>) .exec(query1) .pause() .exec(query2) ...
  • 16.
    Simulations Simulations are wherewe define the amount of load we want to inject into our servers Things required to construct a simulation: ● Scenario ● Protocol ● Assertions Syntax: setUp(<scenario>.inject(<injection_step>)) .protocols(<protocol_name>) .assertions(<condition>)
  • 17.
  • 18.
  • 19.
    References & credits ●http://gatling.io/ ● https://github.com/lkishalmi/gradle-gatling-plugin ● http://www.mbtest.org/ ● https://www.thoughtworks.com/insights/blog/gatling-take-your-performance-tests-next-level ● http://gatling.io/#/cheat-sheet/2.1.7
  • 20.