0

Our automated QA test cases are scheduled and executed by Jenkins. I have to run the test cases on different environments say UAT , STAGE and PROD (as they have different test data) and these test cases are 'grouped' as SANITY , REGRESSION and BATS. I'm using maven + testNG (surefire plugin) to build and execute it .

Now I need to run this as jobs in Jenkins as 'BATS in STAGE' or say 'REGRESSION in DEV' etc. For this , I thought best approach would be, in Jenkins jobs confis, call something like ..

mvn test -Denv=STAGE -Dgroup=SANITY

Other option is setting the params ( env and group) in system variables of Jenkins and go from there.

But I'm facing some major blocks as raised in a different post here ..

How to pass java code a parameter from maven for testing

This looks like a common requirement , has anyone addressed this before ? Is my approach correct, any better way of doing it ?

Please suggest.

Community
  • 1
  • 1
Girish
  • 1,981
  • 3
  • 17
  • 18

2 Answers2

1

You can create seperate maven build profiles for each test scenario/environment and then set their activations based upon command line parameters or environment variables set in Jenkins.

EDIT:

You would essentially have a profile for each test scenario and then you would use the inclusion/exclusion configuration of the surefire-plugin to control which tests fired. Ideally you could run all of that via a top level test class so each set of "groups" as you are calling them would have some sort of AllTests.java class that fired the underlying test suite.

   <profile>
    <id>Stage</id>
    <activation>
      <activeByDefault>false</activeByDefault>
    </activation>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.4</version>
            <configuration>
              <includes>
            <include>**/Sanity/AllTests.java</include>
              </includes>
            </configuration>
          </plugin>
        </plugins>
  </profile>
gregwhitaker
  • 13,124
  • 7
  • 69
  • 78
  • Thanks for the reply, is this not a over kill, is there any simplified approach you can suggest please. This looks like a common requirement. – Girish Nov 07 '12 at 21:38
  • I don't believe that it is overkill. You have to have a way to tell the plugin which tests to run/exclude and the way to do that is via the configuration element. So in maven if you want different behavior in different scenarios using the same POM you create different profiles. – gregwhitaker Nov 07 '12 at 22:05
  • Thanks for your help, looks like instead of creating the profile for each test scenario, this can be achieved in more easier way http://stackoverflow.com/questions/13245411/pass-a-java-parameter-from-maven-for-testng/13631898#comment19219379_13631898 , what do you think ? – Girish Dec 18 '12 at 21:43
0

Assuming you're using the Build section to run "mvn test", here's what worked for me. I went to the same posting OP mentioned, but found this simpler way.

(Jenkins configure page for the job)

Build
Invoke Maven 3
  Maven Version [<latest version>]
  Root POM      [pom.xml]
  Goals and options [test -Denv=STAGE -Dgroup=SANITY]

You can also parameterize the build and use the parameter for the options as below.

Goals and options [test -Denv=$PARAM_ENV -Dgroup=$PARAM_GROUP]