How to perform Junit Testing in Jenkins

Last updated on May 28 2022
Uma Kulkarni

Table of Contents

How to perform Junit Testing in Jenkins

Jenkins – Unit Testing

Jenkins provides an out of box functionality for Junit, and provides a host of plugins for unit testing for other technologies, an example being MSTest for .Net Unit tests. If you go to the link https://wiki.jenkins-ci.org/display/JENKINS/xUnit+Plugin it will give the list of Unit Testing plugins available.

How to perform Junit Testing in Jenkins

How to perform Junit Testing in Jenkins
How to perform Junit Testing in Jenkins

Example of a Junit Test in Jenkins

The subsequent example will consider

• A simple HelloWorldTest class based on Junit.
• Ant as the build tool within Jenkins to build the class accordingly.

Step 1 − Go to the Jenkins dashboard and Click on the existing HelloWorld project and choose the Configure option

How to perform Junit Testing in Jenkins
How to perform Junit Testing in Jenkins

Step 2 − Browse to the section to Feature a Build step and choose the option to Invoke Ant.

How to perform Junit Testing in Jenkins
How to perform Junit Testing in Jenkins

Step 3 − Click on the Advanced button.

How to perform Junit Testing in Jenkins
How to perform Junit Testing in Jenkins

Step 4 − Within the build file section, enter the location of the build.xml file.

How to perform Junit Testing in Jenkins
How to perform Junit Testing in Jenkins

Step 5 − Next click the option to Feature post-build option and choose the option of “Publish Junit test result report”

How to perform Junit Testing in Jenkins
How to perform Junit Testing in Jenkins

Step 6 − Within the Test reports XML’s, enter the location as shown below. Ensure that Reports is a folder which is created within the HelloWorld project workspace. The “*.xml” basically tells Jenkins to pick up the result xml files which are produced by the running of the Junit test cases. These xml files which then be converted into reports which can be viewed later.

Once done, click the Save option at the end.

How to perform Junit Testing in Jenkins
How to perform Junit Testing in Jenkins

Step 7 − Once saved, you can click on the Build Now option.

Once the build is completed, a status of the build will show if the build was successful or not. Within the Build output information, you’ll now notice an featureitional section called Test Result. In our case, we entered a negative Test case so that the result would fail just as an example.

How to perform Junit Testing in Jenkins
How to perform Junit Testing in Jenkins

One can go to the Console output to see further information. But what’s more interesting is that if you click on Test Result, you’ll now see a drill down of the Test results.

How to perform Junit Testing in Jenkins
How to perform Junit Testing in Jenkins

So, this brings us to the end of blog. This Tecklearn ‘How to perform Junit Testing in Jenkins’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Jenkins and build a career in DevOps domain, then check out our interactive, Continuous Integration with Jenkins Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Continuous Integration with Jenkins

Continuous Integration with Jenkins Training

About the Course

Tecklearn has specially designed this Continuous Integration with Jenkins Training Course to advance your skills for a successful career in this domain. This course helps you learn server automation, continuous integration, build and configuration tools, Jenkins master-slave architecture, different types of plugins, implementing automated testing and more through hands-on projects and exercises. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Jenkins.

Why Should you take Continuous Integration with Jenkins Training?

• Average salary of Jenkins Professional is $110k (Indeed.com Salary Data)
• Jenkins is an open-source automation server which enables developers around the world to reliably build, test, and deploy their software.

What you will Learn in this Course?

Introduction to DevOps

• What is Software Development
• Software Development Life Cycle
• Why DevOps?
• What is DevOps?
• DevOps Lifecycle
• DevOps Tools
• Benefits of DevOps
• How DevOps is related to Agile Delivery
• DevOps Implementation

Continuous Integration with Jenkins

• Introduction to Continuous Integration and Jenkins
• Jenkins Management
• Jenkins Master Slave Architecture
• Tools Required for CI
• Understanding CI/CD Pipelines
• Creating an end-to-end automated CI/CD Pipeline
• Jenkins Versions

0 responses on "How to perform Junit Testing in Jenkins"

Leave a Message

Your email address will not be published. Required fields are marked *