Ernest Duodu Ernest is a Java developer. Outside programming, he also enjoys a wide variety of hobbies which includes sky-diving, photography, exercising and listening to music.

Setting up Continuous Testing with Jenkins

2 min read

Whether working on a small or or large project, it is always crucial to have some form of testing.
At IDR Solutions we spend a lot of time on Testing. Testing is always useful and time saving and helps you know when you have broken your code base or build when you introduce changes to it. Imagine if you run your test occasionally, now after 10 commits/pushes you decide to run the test. To your surprise, the build now fails. It is very difficult to tell what commit broke the build. If not lucky, you will have to revert Ten times to trace the issue.

Now this is when Jenkins comes in handy.

What is Jenkins?

It is a continuous Integration Server. Basically, what is does is, it can be configured to runs your tests each time there is a change to your code base. In this case when your build breaks, you get a quick notification and you can tell what code change exactly broke the build.
It is built on Java so it is a 100% cross-platform tool.

Installing Jenkins

You can install Jenkins as a native application or download the war file and deploy Jenkins from it. You can get the downloads from here. I will go ahead and download the .war.
NB if your testing will involve GUI testing, i will advice you deploy Jenkins from the war file (We use to run the native app and had problems when it came to GUI testing ).

Starting up Jenkins

On command line, type in java -jar {Path to downloaded Jenkins directory}/jenkins.war NOTE you need to have jdk installed. You should see Jenkins starting up.

Screenshot 2015-06-24 16.12.08
Once up and running, open you browser and type in localhost:8080. This should open up Jenkins Dashboard.

Screenshot 2015-06-24 16.18.27

Setting up Email Notification

Click on Manage Jenkins -> Configure System. Scroll to email section and fill in the details and Save.

Screen Shot 2015-06-24 at 17.16.41

Testing your Project

I will assume your project is hosted on GitHub. To test your GitHub hosted projects, you need to install a plugin on Jenkins.
In you Jenkins dashboard go to Manage Jenkins -> Manage Plugins -> Available (Tab) and enter GitHub in the Filter field, select GitHub Plugin and click on Download now and install after restart.

Screenshot 2015-06-24 16.34.58
Once clicked wait for all need plugins are downloaded and restart Jenkins.

Screenshot 2015-06-24 16.35.39
To restart Jenkins just type localhost:8080/restart in your browser.

Adding Your First Jenkins Job

Click on create a new job or New Item. Select Freestyle project and give your Job a name. I will call mine testSA (Test Static Analysis) and click OK.
Now at you dashboard, select the job you just created and click on configure at the left side.

Screen Shot 2015-06-24 at 17.22.09
 

Fill in the spaces as follows

Description : Run Static Analysis

Tick Discard Old Builds (Up to you)

  • Strategy : Log Rotation
  • Days to keep builds : blank
  • Max # of builds to keep : 1

Source Code Management
Select GIT
Repository URL : url to your git source code
Credentials : your credentials
Branches to build (Branch Specifier ) : */master

Build Triggers
Select Poll SCM
Schedule : *****

Build
Click add build step and select “Execute Windows batch command” for Windows or “Execute Shell” for Linux/MacOS
Now you can pass in your test build script into that Command textBox.

Post-build Actions
Click E-mail Notification Recipients – your@email.addresss
Select Send e-mail for every unstable build & Send separate e-mails to individuals who broke the build.
Now save it and lets do our first build. Click on the schedule build button.

Screen Shot 2015-06-24 at 18.21.49
This will pull source from your remote repository and run the test on it.

Screen Shot 2015-06-24 at 18.33.12

Note This will happen each time you push to your remote repository.

You should now see something like this if it passes

Screen Shot 2015-06-24 at 18.23.05

Or this each time it fails

Screen Shot 2015-06-24 at 18.41.15

You will also get an email notification if it fails ( with the reason why it failed).

Screen Shot 2015-06-24 at 18.43.34

Tip

If you want to build a project using two Git repositories you can do so by using the Multiple SCMs (it is a plugin, will will have to install). You will need to configure Jenkins to pull projects to Local subdirectories.

You can install the plugin the same way we did for git. type in Multiple SCMs this time.

Screen Shot 2015-06-24 at 18.53.49
Now in configurations, select the Multiple SCMs and fill in details.

Screen Shot 2015-06-24 at 19.02.46

Hopefully you have found this quick guide useful. In the next article, i will show you how to add your own Static Analysis test using PMD.



Our software libraries allow you to

Convert PDF to HTML in Java
Convert PDF Forms to HTML5 in Java
Convert PDF Documents to an image in Java
Work with PDF Documents in Java
Read and Write AVIF, HEIC, WEBP and other image formats
Ernest Duodu Ernest is a Java developer. Outside programming, he also enjoys a wide variety of hobbies which includes sky-diving, photography, exercising and listening to music.