2

Pretty new to Java and programming in general, doing a lot of reading and self-learning. I managed to create a Project with a good set of test classes that go out and test a specific Service that I also created, just a mock though.

I currently work with only 1 env, but in the very near future I'll have two, I want to simulate different tests on different environments and this is where I'm bit stuck.

What is the best infra to help me with properties for different envs, something that will integrate easily with a Jenkins pipeline? To clear out my question/need - I want a test to be able to run with different params on different envs, for QA it will be URL1, USER1, PASS1, and for SBX it will be URL2, USER2, PASS2...

If my question is not clear, please help me clarify it :) I'm using Java8, Junit5, and Gradle

Many thanks in advance!

P.S. - I've been reading on working with different envs with a properties file, I know about that, I'm asking if there's a better way?

Dmoy
  • 57
  • 7

2 Answers2

1

For Maven, please try to create two different profiles for test and dev env in pom.xml file

<profiles>

        <profile>
            <id>Test</id>
            <properties>
                <key1>value1</key1>
                <key2>value2</key2>
            </properties>
        </profile>

        <profile>
            <id>Dev</id>
            <properties>
                <key1>value1</key1>
                <key2>value2</key2>
            </properties>
        </profile>

    </profiles>

In Jenkins pipeline use -p in maven cmd to load particular profile

for ex :- maven clean install -p Test

Sarjit
  • 799
  • 7
  • 9
0

If you going to use docker for deployments, following is the solution that I have used and found better -

You can also pick such properties from environment variable, In docker when you start a container you can provide all the environment variable which will be visible to the application running in that container. Environment variables can be passed as argument or via file both.

Picking properties from environment variable is independent of using docker. It's just that it's more convenient when its comes with docker. How ever if your QA, Staging, Production machines are fixed you can go and set these environment variables on the machine itself if you are running application without docker.

Saurav Kumar Singh
  • 1,352
  • 7
  • 18