Gatling: How to setUp and tearDown scenario
Asked Answered
G

2

10

I have a Gatling test which should do the following:

  1. create user once
  2. retrieve user's data according to specific load model. Actual load testing.
  3. delete user after when done

Question: how to emulate this with Gatling? If I chain calls like :

val scn = scenario("Test scenario").exec(_create-user_).exec(_retrive-user_).exec(_delete-user_)
setUp(scn).protocols(httpConf))

then creating and deleting user will be part of the test.

Glorify answered 21/3, 2016 at 11:8 Comment(0)
R
18

You can use the before and after hooks to create and delete the user.

class RetrieveUserSimulation extends Simulation {

  before {
    // create user
  }

  setUp(scn).protocols(httpConf)

  after {
    // delete user
  }

}

You'll have to issue the create and delete HTTP requests manually. before and after take => Unit thunks, not Scenarios.

Radnorshire answered 13/7, 2016 at 22:33 Comment(1)
I tried something similar here #63386659 but I don't see POST requests only the one in the scenarioCharlottetown
S
0

In before hook we can call a method which can have below code.

val httpClient = HttpClientBuilder.create.build
val httpResponse = httpClient.execute(new HttpPut(urlString))
println("StatusCode - " + httpResponse.getStatusLine.getStatusCode)
httpClient.close()

We can use HttpGet as well. Here used apache library

example : org.apache.http.impl.client.HttpClientBuilder
Sensory answered 22/6, 2020 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.