gpt4 book ai didi

java - TestNG:在 Eclipse 中的 DataProvider 中返回 Iterator 时出现 ClassCastException

转载 作者:行者123 更新时间:2023-12-01 17:03:07 26 4
gpt4 key购买 nike

在我的 TestNG 测试中,我使用返回 Iterator 对象的 DataProvider,但是当我运行测试时,出现错误。有人可以解释一下为什么这是错误的以及我应该做什么来解决它吗?

Eclipse 版本:

Eclipse Java EE IDE for Web Developers.

Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200

Java版本

java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

数据提供商

  @DataProvider(name = "SmokeTestData", parallel = true)
public Iterator<SmokeTestData> smokeTestData(ITestContext context) {
String fileName = context.getCurrentXmlTest().getParameter("filename");
int numberOfTests = SmokeTestData.getNumberOfTests(fileName, true);
SmokeTestData[] testSuiteData = new SmokeTestData[numberOfTests];
for (int i = 1; i <= numberOfTests; i++) {
testSuiteData[i-1] = new SmokeTestData(fileName, i);
}
return (Stream.of(testSuiteData)).iterator();
}

测试

 @Test(description = "Smoke Test", dataProvider = "SmokeTestData", groups =
{"SmokeTest"})
@Description("Smoke Test")
@Severity(SeverityLevel.NORMAL)
public void smokeTest(SmokeTestData smokeTestData) {
selectEnv(smokeTestData.getUrl());
loginPage.get().smoketest(smokeTestData.getEnvironment(), smokeTestData.getEmail(), smokeTestData.getPassword());
serviceAvailabilityPage.get().smoketest();
referralRequestStatusPage.get().smoketest();
}

数据

Environment,Url,Email,Password
DE,https://somedomain.com/index.php/login,user@somedomain.com,somePW!1
IN,https://somedomain.com/index.php/login,user@somedomain.com,somePW!1
NM,https://somedomain.com/index.php/login,user@somedomain.com,somePW!1
MI,https://somedomain.com/index.php/login,user@somedomain.com,somePW!1
NV,https://somedomain.com/index.php/login,user@somedomain.com,somePW!1
AK,https://somedomain.com/index.php/login,user@somedomain.com,somePW!1

错误:

java.lang.ClassCastException: data.SmokeTestData cannot be cast to java.base/[Ljava.lang.Object;
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1102)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)

感谢您提前提供的任何帮助!!

最佳答案

我通过完全卸载 Eclipse(包括以下文件夹)并清空垃圾箱解决了此问题。

  • ~/.eclipse
  • ~/Library/Caches/org.eclipse.platform.ide
  • ~/Library/已保存的应用程序状态/org.eclipse.platform.ide.savedState
  • ~/Library/Preferences/org.eclipse.platform.ide.plist

然后安装了 Eclipse IDE for Java Developers 版本 2018-09 和 TestNG 插件。

关于java - TestNG:在 Eclipse 中的 DataProvider 中返回 Iterator 时出现 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61486133/

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