1
我試圖在Eclipse中運行用TestNG下面的程序,並正在錯誤,如下圖所示:noClassDefFound錯誤使用TestNG
代碼:
package TestNGPackage;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
public class ParameterizedClass {
@Test(dataProvider = "Database")
public void UserDetails(String n, String s) {
System.out.println("ID and names are: "+ n + s);
}
@DataProvider
public Object[][] Database() {
Object[][] data= new Object[3][2];
//rows- number of test to be repeated or number of test data set
// cols- number of parameters in the test data
//first row
data[0][0]="Controls team";
data[0][1]="Vandee";
//second row
data[1][0]="Risk team";
data[1][1]="Raghu";
//third row
data[2][0]="Forecast team";
data[2][1]="Surbhi";
return data;
}
}
錯誤:
[TestNG] Running:
C:\Users\Vandhana\AppData\Local\Temp\testng-eclipse-538297309\testng-customsuite.xml
[Utils] Attempting to create C:\Java Programs\TestNG\test-output\Default suite\Default test.xml
[Utils] Directory C:\Java Programs\TestNG\test-output\Default suite exists: true
SKIPPED: UserDetails
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(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 27 more
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
===============================================
提供的類定義仍然會出現此錯誤。當我使用TestNG運行時,我的其他程序工作正常,所以我懷疑jar文件問題。
我點擊了Eclipse的下載新的軟件,並通過添加TestNG的。我們是否需要單獨添加其他文件? – Vandee
重複的建議添加番石榴應該工作。 –
太棒了!我下載並將jar添加到我的proj文件夾,它現在可以工作。謝謝! – Vandee