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
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Test Driven Development Using TestNG, Gradle
  • Selenium WebDriver and TestNG: Find Perfect Match for Automation Testing
  • Selenium Java Tutorial: Automation Testing of a User Sign Up Form
  • How to Use the TestNG Framework for Creating Selenium Scripts

Trending

  • How to Submit a Post to DZone
  • DZone's Article Submission Guidelines
  • Demystifying Project Loom: A Guide to Lightweight Threads in Java
  • Revolutionizing Software Testing
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. TestNG Exception: org.testng.TestNGException: DataProvider should be static

TestNG Exception: org.testng.TestNGException: DataProvider should be static

Jagadeesh Motamarri user avatar by
Jagadeesh Motamarri
·
Sep. 05, 13 · Interview
Like (0)
Save
Tweet
Share
13.71K Views

Join the DZone community and get the full member experience.

Join For Free

Issue

If you see below exception while running your TestNG test case, you probably forgot to set the methods in your Data Provider Class to static.

Source code of the data provider that caused the above exception -

package com.skilledmonster.common;
import org.testng.annotations.DataProvider;
/**
* Data Provider class for TestNG test cases
*
* @author Jagadeesh Motamarri
* @version 1.0
*/
public class TestNGDataProvider {
/**
* Data Provider for testing sum of 2 numbers
*
* @return
*/
@DataProvider
public Object[][] testSumInput() {
return new Object[][] { { 5, 5 }, { 10, 10 }, { 20, 20 } };
}
/**
* Data Provider for testing multiplication of 2 numbers
*
* @return
*/
@DataProvider
public Object[][] testMultipleInput() {
return new Object[][] { { 5, 5 }, { 10, 10 }, { 20, 20 } };
}
}
?

Solution

If you want to put your data provider in a different class, it needs to be a static method and you specify the class where it can be found in the dataProviderClass attribute.

Source code that fixed the above exception

?
package com.skilledmonster.common;
import org.testng.annotations.DataProvider;
/**
* Data Provider class for TestNG test cases
*
* @author Jagadeesh Motamarri
* @version 1.0
*/
public class TestNGDataProvider {
/**
* Data Provider for testing sum of 2 numbers
*
* @return
*/
@DataProvider
public static Object[][] testSumInput() {
return new Object[][] { { 5, 5 }, { 10, 10 }, { 20, 20 } };
}
/**
* Data Provider for testing multiplication of 2 numbers
*
* @return
*/
@DataProvider
public static Object[][] testMultipleInput() {
return new Object[][] { { 5, 5 }, { 10, 10 }, { 20, 20 } };
}
}

References: http://testng.org/doc/documentation-main.html#parameters-dataproviders

TestNG

Published at DZone with permission of Jagadeesh Motamarri, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Test Driven Development Using TestNG, Gradle
  • Selenium WebDriver and TestNG: Find Perfect Match for Automation Testing
  • Selenium Java Tutorial: Automation Testing of a User Sign Up Form
  • How to Use the TestNG Framework for Creating Selenium Scripts

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • 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: