Reputation: 2011
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.
Upvotes: 0
Views: 6410
Reputation: 94
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]
Upvotes: 0
Reputation: 13420
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>
Upvotes: 1