Scala object is initialized in setUp. Why not in before?


I have a configuration (Config in below code) object, that I use for reading properties and system variables.
In below code Config is addressed both form before and setUp. But it’s initialized in setUp.
The result is that values, which are populated in Config, are nulls because before part was not done yet.

import com.bk.cfg.Config
import com.bk.core.Tests
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation
import io.gatling.http.Predef.http
import scala.concurrent.duration._

class SomeTest extends Simulation {
val logger = org.slf4j.LoggerFactory.getLogger(“SomeTestLogger”)
var appProtocol =
.acceptEncodingHeader(“gzip, deflate, br”)

before{“Start test”)
val testId = doSomeHttpCall()
val users = Config.users“Starting simulation”)

.inject(rampUsers(10).during(60 seconds))

This is the log:

12:41:26.383 [INFO ] i.g.c.c.GatlingConfiguration$ - Gatling will try to use ‘gatling.conf’ as custom config file.
12:41:26.920 [INFO ] a.e.s.Slf4jLogger - Slf4jLogger started
12:41:27.370 [INFO ] ConfigLogger - Run Config
12:41:27.372 [INFO ] ConfigLogger - loadEnvProperties
12:41:27.378 [INFO ] ConfigReaderLogger - Done loading environment configuration
12:41:27.378 [INFO ] ConfigLogger - loadSimulationProperties
12:41:27.379 [INFO ] ConfigReaderLogger - Using default configuration file…
12:41:27.379 [INFO ] ConfigReaderLogger - Done loading simulation configuration
12:41:27.401 [INFO ] SomeTestLogger - Start test

12:41:27.406 [INFO ] SomeTestLogger - Starting simulation

As you can see, Config is loaded before the ‘before’ stage.
If Config reference is removed from setUp, the log entries will be reversed (SomeTestLogger, then ConfigLogger).