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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Integrating Jenkins With Playwright TypeScript: A Complete Guide
  • Biggest Software Bugs and Tech Fails
  • Why You Need to Shift Left With Mobile Testing
  • The Art of Manual Regression Testing

Trending

  • Testing SingleStore's MCP Server
  • Integrating Security as Code: A Necessity for DevSecOps
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  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 user avatar
Vakul Gotra
DZone Core CORE ·
Updated Feb. 07, 18 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
18.3K Views

Join the DZone community and get the full member experience.

Join For Free

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

  • Integrating Jenkins With Playwright TypeScript: A Complete Guide
  • Biggest Software Bugs and Tech Fails
  • Why You Need to Shift Left With Mobile Testing
  • The Art of Manual Regression Testing

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!