Gatling is reading resource file in src/main not in src/test

In my project I have this structure:

SampleProjectModule
----------src
----------------test
---------------------java
------------------------package1
------------------------package2
------------------------package3
---------------------resources
------------------------env1
--------------------------gatling-env1.conf
------------------------env2

When I try executing the gatling test it doesn’t read the gatling-env1.conf file in src/test. But if I try to create src/main/java/resources/env1/gatling-env1.conf it suddenly works and reads the file. But I want it to read from src/test/resources/env1/gatling-env1.conf not from src/main/…

Hi @Veron,

Welcome aboard!

This subject is not specific to gatling.
You’ll have to make the difference between reading a file (from the working directory) and reading a resource in the classpath.

We advise to do the later: reading a resource in the classpath, as it is the only reliable way of reading data in a project (reading a provided file by configuration is fine, but a project data is usually in a jar, hence in the classpath)

Here one article from Baeldung about this subject (and a direct link to the interesting chapter): How to Read a File in Java - 3. Reading a File from the Classpath

Hope it helps!

Cheers!

1 Like