Make Money Online AUTOMATION Jenkins Tutorial #6 – How to Run Automation Tests in Jenkins

Jenkins Tutorial #6 – How to Run Automation Tests in Jenkins

Jenkins Tutorial #6 – How to Run Automation Tests in Jenkins post thumbnail image


As a general rule, it’s a good idea to run your automation tests in Jenkins on a regular basis. This gives you confidence that your code is working as expected and that you haven’t introduced any regressions.

There are many different ways to run automation tests in Jenkins, but in this tutorial we’ll focus on two of the most popular: using the built-in Jenkins plugins and using the open source TestNG framework.

We’ll start by looking at how to run automation tests using the built-in Jenkins plugins. We’ll then look at how to use TestNG with Jenkins.

Using the Built-In Jenkins Plugins

Jenkins has a number of built-in plugins that you can use to run your automation tests. The most popular plugins are the JUnit plugin and the NUnit plugin.

To use either of these plugins, you first need to add them to your Jenkins instance. This can be done via the Manage Plugins screen in the Jenkins web UI. Once you have installed the plugins, you can create a new job and select one of the plugin types as your build step.

The JUnit plugin is probably the most widely used Jenkins plugin for running automation tests. It can be used to execute both JUnit and TestNG tests. To use the JUnit plugin, you first need to add it to your project’s POM file:

org.apache.maven.plugins maven-surefire-plugin 2.19 testng.xml

Note that we have configured the surefire plugin to use a TestNG suite XML file (testng.xml). This file defines our TestNG test suite and includes information about which tests should be executed and how they should be executed. We’ll look at how to create this file in the next section.

Once you have added the surefire plugin to your POM file, you can execute your TestNG tests by running the following command:

mvn test -Dtest=MyTestClass1,MyTestClass2

This will execute all of the tests in MyTestClass1 and MyTestClass2 . You can also specify wildcards (*) in the class names, so the following command will execute all of the tests in all of the classes in MyTestPackage :

mvn test -Dtest=MyTestPackage*

Related Post