How To Execute TestNG Tests Using Jenkins | Software Testing Material

In the earlier post, we have seen How To Run TestNG Scripts (testng.xml) Using Command Prompt and Using Batch file (.bat). In this post, we see how to execute TestNG Tests Using Jenkins. To do this, we need to have the following

i. TestNG Project
ii. Jenkins – Check this post on Installation of Jenkins.

Don’t Miss: Selenium Complete Tutorial

How To Execute TestNG Tests Using Jenkins

Let’s get started on How To Create TestNG Project.

Step 1: Creating TestNG Project. Follow this link to create TestNG Project.

Must Read: TestNG Complete Tutorial

Step 2: Installing Jenkins. Follow this link for Installing Jenkins

We have TestNG Project and Jenkins ready. Now, lets execute TestNG Tests Using Jenkins.

In the below image, you could see the project structure and testng.xml

Open Jenkins. By default it will be ‘localhost/8080’

Click on ‘New Item’

Enter an Item Name of your preference. I gave the name as ‘TestNGProject‘. In the screenshot below, you could see the name as MavenProject (ignore it).

Select ‘Freestyle Project’ and click on OK button

Now, click on item ‘TestNGProject’

Under General Tab, you could see ‘TestNGProject‘. Click on ‘Advanced‘ button to add the custom workspace.

Now select the ‘Use Custom Workspace‘ checkbox and enter the path of your workspace. My workspace is available at this location ‘D:\DeleteNow\TestNGProject

Scroll down to ‘Build‘ option. Click on ‘Add Build Step‘ and choose the value ‘Execute Windows batch command‘ from the drop down list.

My batch file name is ‘BatchRun.bat’ and I specified the same here.

Click on ‘Apply‘ and ‘Save

We have created a new project ‘TestNGProject‘ with the configuration to run TestNG Tests using Jenkins. You could see in the below screenshot.

Let’s execute it now. Click on ‘Build Now‘ button. It will invoke testng.xml from the batch file.

Right click on Build Number (here in my case it is #1) and click on Console Output to see the result.

You could see the print statement ‘softwaretestingmaterial.com’ and Build Status ‘Success’

This way, we could execute TestNG Tests using Jenkins. In the next post, we see how to generate TestNG Reports after the completion of execution. Same way, we could execute Maven Project Using Jenkins.

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

24 thoughts on “How To Execute TestNG Tests Using Jenkins | Software Testing Material”

  1. Hello sir,
    I just want to know that, I am facing an issue after creating batch file. so my question is that, for creating batch file to run testNG is it neccessary to ad mozilla driver?

    Reply
  2. ?xml version=”1.0″ encoding=”UTF-8″?
    !DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”
    suite name=”Suite”

    test name=”FirefoxTest”
    parameter name=”browser” value=”Firefox”>

    /suite

    Reply
  3. ?xml version=”1.0″ encoding=”UTF-8″?
    !DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”
    suite name=”Suite”

    test name=”FirefoxTest”
    parameter name=”browser” value=”Firefox” parameter
    classes
    class name=”scripts.testJenkins”
    classes
    test

    suite

    Reply
  4. Hi,

    I am unable to run batch i am facing total test run:0 skip:0 issue while trying to run the testng.xml file in CMD.

    Reply

Leave a Comment

Share via
Copy link
Powered by Social Snap