How to setup gatling test scenario

özkan pakdil - Sep 12 '23 - - Dev Community

In a Gatling test, the setUp method is used to specify the scenario that will be run during the test. In the code below, the scenario is specified using the scn variable, which presumably refers to a scenario that has been defined elsewhere in the code.

val nbUsers = Integer.getInteger("users", 1000)
val myRepeat = java.lang.Long.getLong("repeat", 2)

val httpProtocol = http.baseUrl("http://localhost:8080")
val scn = scenario("hello").repeat(myRepeat.toInt) {
    exec(http("GetApplicationInfo")
        .get("/hello")
        .check(status.is(200))
        .check(jsonPath("$.name")))
}

setUp(
    scn.inject(
        rampUsers(nbUsers) during (5 seconds)
    ).protocols(httpProtocol)
)

Enter fullscreen mode Exit fullscreen mode

The inject method is used to specify how the users will be introduced into the system under test. In this case, the rampUsers method is used to gradually increase the number of users over a period of 5 seconds. This is known as a ramp-up. The total number of users to be injected is specified by the nbUsers variable.

Finally, the protocols method is used to specify the protocol that will be used to send requests to the system under test. In this case, the httpProtocol variable is used, which presumably refers to an HTTP protocol.

Overall, this code is setting up a Gatling test that will gradually ramp up the number of users over a period of 5 seconds, and will use the specified HTTP protocol to send requests to the system under test.

You can find all running gatling project here you can see the result of that scenario in here.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player