gpt4 book ai didi

java - testNG 出现 noClassDefFound 错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:18:43 24 4
gpt4 key购买 nike

我尝试在 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 文件问题。

最佳答案

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

关于java - testNG 出现 noClassDefFound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39091820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com