How can I initialize the gatling configuration only once?

I am loading the application related config in BasicSimulation class and this class is being inherited by all other simulation test scripts in my project. This class contains something like this

enter image description here

The sample simulation script is like below :

enter image description here


  1. For every GET request where I am using variable present in BasicSimulation class(i.e. header), it is initializing the conf every time. How can I fix this?
  2. How can I call the existing scenarios present in different simulation classes i.e do I need to create the instance of each simulation class separately or is there any other way also?

it is initializing the conf every time

No it’s not.

I don’t know Stéphane what to say but thanks for your response on this. Maybe I am doing something wrong in the scripts.

conf is a val, not a def, so value is only computed once.

If your code is written as you described, then under the covers, Scala is initializing the variables exactly once. If you show them as “val” here, but your code says “def”, then yes, it is doing it multiple times. The question is, what are you seeing that makes you think it is being initialized multiple times?

The scenario is just a value, an object, stored in a variable. You may declare that object anywhere you like. And you may reference it from wherever you like, subject to the rules of the language.

We typically define our scenarios in the simulation in which they are run, but nothing says you have too. I actually make it a habit of defining my scenarios outside of the simulation, because I almost always run the scenario in at least two or three different simulations. One is a unit test that lets me verify that the scenario is written correctly, one is an isolated load test that loads up the system with only that scenario, and the final one is a combined load test that runs many different scenarios all concurrently.

The fact that you are asking this question means it’s time to dig in and learn Scala. :slight_smile: