DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption
  • Web App Load Testing Using Maven Plugins for Apache JMeter, and Analyzing the Results
  • The Immune System of Software: Can Biology Illuminate Testing?
  • Integrating Jenkins With Playwright TypeScript: A Complete Guide

Trending

  • Beyond the Wall of Charts: How Advanced Observability Displaced the Telemetry Dashboard
  • Why Role-Based Access Control Fails for AI Agents — and How to Fix It With Memory Lineage Engines
  • The Permission Was Valid. The Action Was Not Authorized.
  • Moving 900+ GB of Prometheus Without a Cutover Weekend

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Jenkins TestNG Failed Test Cases for Maven

Jenkins TestNG Failed Test Cases for Maven

A former Jenkins newbie provides some clarification on a common issue that other Jenkins initiates might face using TestNG and WebDriver.

By 
Vakul Gotra
·
Updated Feb. 07, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
18.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

As I switched from a software testing company to another, I was introduced to Jenkins for the first time. Being a newbie to the tool, I got stuck on a point where I would run the command: 

cd path to workspace
mvn test -DtestNG.file=/target/surefire-reports/testng-failed.xml


Here, it would run testng.xml instead of running testng-failed.xml. Now I often find new testers struggling through this same dilemma. Here’s what happened:

Once I configured it on my Windows desktop, I used TestNG and Selenium Webdriver for writing test cases to run failed test cases twice before considering that they are failing. Moving forward, I created a job in Jenkins which mapped to my workspace and run the testng.xml.

I specified the path of testng.xml in pom.xml. and created a maven project and used the pom.xml for running test cases. Once I figured out that I was getting a successful run of all test cases, I was able to achieve surefire reports of the tests.

Unfortunately, when I ran the above command, it would automatically run testng.xml instead of running the expected testng-failed.xml. I was not sure if I was following the correct path for running failed test cases.

So, I approached a senior of the software testing company I work with now and thankfully he was able to provide me with a solution. I also found out that this is a common scenario software testers come across when they are introduced to Jenkins initially. This is what was going wrong:

The failed-testng.xml were getting deleted whenever I would re-run the tests in Post task under Jenkins. This was simply because when you run "mvn clean," it automatically deletes the target folder where the failed-testng.xml files were present. You will have to access the Jenkins workspace if you want to be assured, but it may be a case that your software testing company may not have the access to it.

You can resolve the issue by following these steps:

First your pom should be configurable to run the tests from command line:

<plugin>

<groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-surefire-plugin</artifactId>

    <version>2.19.1</version>

    <configuration>

      <forkCount>0</forkCount>

      <suiteXmlFiles>

        <suiteXmlFile>src/test/resources/${suiteXmlFile}</suiteXmlFile>

      </suiteXmlFiles>

    </configuration>

  </plugin>


Copy or move the failed-testng.xml from the target folder to any other location within the framework, except target and test-output folder. This is simply because these folders will be deleted when you run the command "mvn clean".

Now, configure Jenkins for the Post build to run the failed-testng.xml.

Here is the Maven plugin to move file from one location to another:

<plugin>

    <artifactId>maven-resources-plugin</artifactId>

    <version>3.0.1</version>

    <executions>

      <execution>

        <id>copy-resources</id>

        <!-- here the phase you need -->

        <phase>validate</phase>

        <goals>

          <goal>copy-resources</goal>

        </goals>

        <configuration>

          <outputDirectory>${basedir}/target/failed-testng.xml</outputDirectory>

          <resources>         

            <resource>

              <directory>src/</directory>

              <filtering>true</filtering>

            </resource>

          </resources>             

        </configuration>           

      </execution>

</executions>

  </plugin>


Note: This plugin must be executed after the tests execution.

Testing Jenkins (software) Apache Maven TestNG Software testing

Opinions expressed by DZone contributors are their own.

Related

  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption
  • Web App Load Testing Using Maven Plugins for Apache JMeter, and Analyzing the Results
  • The Immune System of Software: Can Biology Illuminate Testing?
  • Integrating Jenkins With Playwright TypeScript: A Complete Guide

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook