Monday, March 23, 2015

Using maven and surefire for test automation

So you have your Junit tests ready, and not you want to run them in CI server like Jenkins.
Assuming that you already use Maven for your Java project, you can configure a profile for each test scenario that later a Jenkins job will run.

Things you need before completing this mission:

  1. Your Java project(configured as Maven project) with some Junit tests 
  2. Jenkins installed
  3. A Jenkins job configured to pull your test code using git or other SCM

Here is a sample of a profile inside pom.xml:
This is the Jenkins job maven configuration:

Some explanations:
1. test is the maven goal and it should never be changed. It tells Jenkins to look for a profile id called "unitTests" (-P stands for Profile), and run all Junit tests that are included in the profile under the "Includes" section. (It is also possible to exclude test and do a lot more. for more info see surefire documentation.
2. As you can see, it is possible (and you should use for making your test framework more flexible and easy to configure between environments, browsers, etc) to send parameters from the job settings to the test themselves. In this job the parameters are: browser and remote machine. You can later access these parameters from the Java code using System.getProperty



No comments:

Post a Comment