testNG出现noClassDefFound错误

时间:2016-08-23 03:22:48

标签: java eclipse testng

我试图在eclipse中使用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文件问题。

2 个答案:

答案 0 :(得分:0)

如果它在不同的上下文中工作,则意味着您有不同的类路径 您是使用maven,gradle还是手动添加库?

答案 1 :(得分:0)

请下载testNG jar并将其添加到lib文件夹,如果使用maven,请添加以下依赖项

 <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
    </dependency>