Data Provider in TestNG gives a class not found exception | Selenium Forum
M
Posted on 04/08/2016
I am using the same code as in the tutorials, I have a sample script for data providers as below :

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class Sample_data_provider {


public class DP {

@Test(dataProvider = "DPER")
public void some1(String b) {
System.out.println("check"+b);
}

@DataProvider
public String DPER() {
String a = "ABCD" ;
return a ;
}
}

}

The above code gives class not found exception. However, when I checked on internet, I found that I need to use attribute @Guice on my public class. However, when I use it, I get error as The type com.google.inject.Module cannot be resolved. It is indirectly referenced from required .class files.

Below is my current code ,

import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;


public class Sample_data_provider {


@Guice
public class DP {

@Test(dataProvider = "DPER")
public void some1(String b) {
System.out.println("dvjdns"+b);
}

@DataProvider
public String DPER() {
String a = "ABCD" ;
return a ;
}
}

}

Please help to get my data providers fixed.

M
Replied on 04/08/2016

remove @Guice.

and run it and then send me the error.


M
Replied on 04/08/2016

[TestNG] Running:
C:\Users\abhilash\AppData\Local\Temp\testng-eclipse--1652328677\testng-customsuite.xml

[Utils] Attempting to create C:\Users\abhilash\workspace\Module9_TestNG_Ant\test-output\Default suite\Default test.xml
[Utils] Directory C:\Users\abhilash\workspace\Module9_TestNG_Ant\test-output\Default suite exists: true
SKIPPED: testMailSending
java.lang.NoClassDefFoundError: com/google/common/primitives/Ints
at org.testng.internal.annotations.JDK15TagFactory.createDataProviderTag(JDK15TagFactory.java:335)
at org.testng.internal.annotations.JDK15TagFactory.createTag(JDK15TagFactory.java:59)
at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:217)
at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:111)
at org.testng.internal.Parameters.findDataProvider(Parameters.java:326)
at org.testng.internal.Parameters.findDataProvider(Parameters.java:261)
at org.testng.internal.Parameters.handleParameters(Parameters.java:418)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1240)
at org.testng.internal.Invoker.createParameters(Invoker.java:980)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1070)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:746)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1189)
at org.testng.TestNG.runSuites(TestNG.java:1104)
at org.testng.TestNG.run(TestNG.java:1076)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
Caused by: java.lang.ClassNotFoundException: com.google.common.primitives.Ints
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 27 more


===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
===============================================

The script is Module9_TestNG_Ant\src\tests\SendMailTest.java from the tutorials.


M
Replied on 04/08/2016

download this and add it to your project.


http://www.java2s.com/Code/Jar/c/Downloadcomgoogleguava160jar.htm


M
Replied on 05/08/2016

Thanks Ashish, It worked !!


M
Replied on 26/07/2017

I am also getting the same error message, also I added jar file which you have mentioned but still getting the same error message.


M
Replied on 26/07/2017

are you executing through maven or ant?