Java By Kiran
Java Training Institute in Pune
Java Training Institute in Pune
Now we will publish the TestNG results using Jenkins TestNG Plugin. This plug-in allows us to publish TestNG results generated using org.testng.reporters.XMLReporter. It helps us see a summary of passed/fail tests as well as passed/fail configuration methods.
Once TestNG plug-in is configured, we can other also configure advanced properties like 'Show Failed Builds?', 'Mark build as unstable on Skipped config/test methods?', 'Escape exception messages?' etc. You can find more details in Jenkins testng-plugin
Let us now see how to configure 'testng-plugin for jenkins' and execute simple program to to see the TestNg Results.
Before proceeding to configure, make sure you have installed Jenkins testng-plugin. You can check here for more details on installing plug-in in Jenkins
After installing testng-plugin, you should be able to view the plug-in in list of installed plug-ins as below : -
Once it is done, now One step that we need to add to the previous article is to “Add post Build Action” and select “Publish TestNG Results” option.' [You only see this option once the plug-in is installed successfully]
After selecting “Publish TestNG Results” option, you should be able to see TestNG XML report pattern which is filled with '**/testng-results.xml' as below along with 'Advanced' button.
That's all we need to Publish TestNG Results in Jenkins. Now click on Build now to view TestNG results. Once the job execution is completed successfully, we should see a link to View TestNG Results as below:
Advanced Parameters in TestNG Plugin
You can click on 'Advanced' button to configure other parameters if required. Example: In the options, if we select 'Mark build as unstable on Skipped tests?', Even if there is any single test is Skipped, it will mark the build as 'Unstable'.
Here is how it shows the unstable build if result has skipped test after execution : -
we have seen executing testng.xml from batch file (.bat) which is an unformatted text file that consists of a series of commands to be executed by the command line interpreter. And we have also seen and executing testng.xml tests from command line,
Before proceeding, create any sample testNGProject, we have already created sample project here and we will execute the same tests here with jenkins help. After creating the sample project, project structure should look like below :
Now here we will see how to invoke batch file with Jenkins. Let us follow below steps to invoke .bat file from jenkins :
In Jenkins, you have an option to create 'New Job' Item, Click on it.
Enter Job name and select "Free-Style Software Project" and then click on 'OK' button.
You should see header as 'Advanced Project Options' and with a button 'Advanced'. Now Click on "Advanced" option which will display multiple options.
Select 'Use custom workspace' and specify your project location (workspace directory) in Directory
Scroll down to see 'Build' option with 'Add Build Step'. In this drop down select value 'Execute Windows batch command' which Runs a Windows batch script for building the project. The text that we enter in the text box will be executed as a batch file. The script will run with the workspace as the current directory which we have specified in step 4.
Job name and select "Free-Style Software Project" and then click on 'OK' button.
Click on Save button. New Job will be created with the configure options that we have defined.
That's It. We have Done.
Now we can execute job file by clicking on the 'Build Now' button which will invoke testng.xml from the batch file. Here the output looks after executing the job: