Fedor
Fedor

Reputation: 669

Gatling: How to setUp and tearDown scenario

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.

Upvotes: 10

Views: 11410

Answers (2)

Nalin
Nalin

Reputation: 1

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

Upvotes: 0

David B.
David B.

Reputation: 5880

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.

Upvotes: 18

Related Questions