Java 错误:无法找到或加载主类 org.testng.remote.RemoteTestNG
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32943504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Could not find or load main class org.testng.remote.RemoteTestNG
提问by cleo
I have written a test suite using TestNG. I have included only one test.java file for my service. I have created the testng.xml file as well. When I run the testng.xml file, I'm getting below error:
我已经使用 TestNG 编写了一个测试套件。我只为我的服务包含了一个 test.java 文件。我也创建了 testng.xml 文件。当我运行 testng.xml 文件时,出现以下错误:
Error: Could not find or load main class org.testng.remote.RemoteTestNG
Please let me know how to fix this. Created the test suite using thislink. I ran the suite using thislink.
请让我知道如何解决这个问题。使用此链接创建了测试套件。我使用此链接运行套件。
Edits:My testng.xml looks like:
编辑:我的 testng.xml 看起来像:
<suite name="TestAll">
<test name="testService">
<classes>
<class name="com.ui.business.service.impl.myservice.test.MyServiceTest"/>
</classes>
</test>
</suite>
I have kept the testng.xml in the root folder. The project compiles with Maven. My service class is in com.ui.business.service.impl.myservice package. When I run the testng.xml with "TestNG Suite", I get this error. Please suggest what to do for resolving this classpath issue.
我将 testng.xml 保存在根文件夹中。该项目使用 Maven 编译。我的服务类在 com.ui.business.service.impl.myservice 包中。当我使用“TestNG Suite”运行 testng.xml 时,出现此错误。请建议如何解决此类路径问题。
回答by Sunita
I can run my tests once I add these dependencies to the project:
一旦我将这些依赖项添加到项目中,我就可以运行我的测试:
hamcrest-all-1.3.jar
hamcrest-core-1.3.jar
hamcrest-integration-1.3.jar
selenium-java-2.46.0-srcs.jar
selenium-java-2.46.0.jar
selenium-server-standalone-2.44.0.jar
testng-6.8-dist.jar
testng-6.8.5.jar
testng.jar
回答by Glenn Mi
I saw this problem when I run testNG in eclipse. I found that it's because the testng jar I included in my build was upgraded from 6.9.9 to 6.9.11. In testng 6.9.11 the class RemoteTestNG is gone. I upgraded by eclipse testng plugin from 6.9.9 to 6.9.11 and the problem is gone.
我在 eclipse 中运行 testNG 时看到了这个问题。我发现这是因为我在构建中包含的 testng jar 从 6.9.9 升级到 6.9.11。在 testng 6.9.11 中,RemoteTestNG 类消失了。我通过 eclipse testng 插件从 6.9.9 升级到 6.9.11,问题消失了。
回答by John Alexander Betts
This worked for me:
这对我有用:
- Right click on your project
- Click on
Properties
- Click on
TestNG
- Uncheck
Use Project TestNG jar
box - Click on
Apply and Close
- 右键单击您的项目
- 点击
Properties
- 点击
TestNG
- 取消
Use Project TestNG jar
复选框 - 点击
Apply and Close
回答by Ashish Gupta
Please follow the below steps, these worked well for me in Eclipse.
请按照以下步骤操作,这些在 Eclipse 中对我来说效果很好。
- Right click on project
- Go to Build path
- Go to Configure build path
- Go to Library
- Ticked TestNG library and if library not added then add TestNG library by click on Add Library button
- Go to next tab Order and Export
- Move TestNG to top
- Add JRE library as well whcih points to JDK no need to move that up just ticked.
- Click on Apply.
- Click on OK.
- Update project
- Maven install.
- Run class as TestNg
- 右键单击项目
- 转到构建路径
- 转到配置构建路径
- 去图书馆
- 勾选 TestNG 库,如果未添加库,则通过单击添加库按钮添加 TestNG 库
- 转到下一个选项卡订购和导出
- 将 TestNG 移至顶部
- 添加 JRE 库以及指向 JDK 的 JRE 库,无需将其向上移动即可。
- 单击应用。
- 单击确定。
- 更新项目
- Maven 安装。
- 将类作为 TestNg 运行
Happy Coding!! Cheers!
快乐编码!!干杯!