在 Eclipse 中:无法找到或加载主 class org.testng.remote.RemoteTestNG

In Eclipse: Could not find or load main class org.testng.remote.RemoteTestNG

配置

我有 2019-12 (4.14.0) 版本的 Eclipse(最近从 2019-03 升级)安装了以下插件(以及其他插件):

TestNG 6.14.3.201902250526
TestNG M2E (Maven) Integration (Optional) 6.14.3.201902250526
TestNG P2 Features 6.14.3.r201802240500

Eclipse 正在 运行对抗 jdk1.8.0_152

在 Eclipse 中,我的 Java 构建路径包括 testng-6.14.3。我尝试将 Eclipse 插件版本与项目中使用的版本相匹配。

Properties -> TestNG下我有所有的默认设置。 "Use Project TestNG.jar".

这里没有设置

有效方法

当我 运行 从命令行使用 Gradle 进行测试时,它们都通过了,没有任何问题。

Eclipse 中没有显示编译错误。

什么不起作用

当我从 Eclipse 运行 进行测试时(通过右键单击 class),控制台显示:

Error: Could not find or load main class org.testng.remote.RemoteTestNG

看来我需要一份 testng-remote.jar。这应该作为插件的一部分安装,还是我打算将其作为依赖项包含在我的 build.gradle 中?

为什么我不能 运行 从 Eclipse 进行测试?我是否需要进一步安装一些东西来解决这个错误?

我试过的

我已经尝试删除并重新安装 TestNG 插件。

您可以尝试将其添加到您的 build.gradle 中吗?

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
        classpath group: 'org.testng', name: 'testng', version: '6.8.+'
    } }

根据您的使用情况更改 testng 版本。

我不记得 gradle 有这样的问题,但它看起来类似于在 maven 上测试的问题(自动构建关闭)。解决方案是重建项目(对于 Maven,它是 ia alt +f5)并且由于这种重建 - 缓存已更新。

您似乎在 Windows 中遇到了错误 https://bugs.eclipse.org/bugs/show_bug.cgi?id=558495。 因此,我将我的版本恢复到 2019-09。

该错误导致本应位于类路径中的 jar 不在类路径中。这会影响具有长类路径的项目。

你有detailed TestNG gradle tutorial

By default, Gradle will run all tests that it detects, which it does by inspecting the compiled test classes. When we specify useTestNG(), Gradle scans for all the methods annotated with @Test and execute them.

Example 1. Below is the basic configuration for the 'test' task

plugins {
    id 'java'
}    
group 'com.test'
version '1.0-SNAPSHOT'    
sourceCompatibility = 1.8    
repositories {
    mavenCentral()
}    
dependencies {
    compile group: 'org.testng', name: 'testng', version: '6.14.3'
}    
test {
    useTestNG()
}

对于 Gradle 使用 testCompile 依赖项:

repositories {
    jcenter()
}     
dependencies {
    testCompile 'org.testng:testng:6.10'
}

对于特定版本你有选择,

  1. 从更新站点安装
  • Select Help / Install New Software...
  • Enter the update site URL in "Work with:" field:
  • Update site for release: http://dl.bintray.com/testng-team/testng-eclipse-release/.
  • Make sure the check box next to URL is checked and click Next.
  • Eclipse will then guide you through the process.
  • You can also install older versions of the plug-ins here. Note that the URL's on this page are update sites as well, not direct download links.
  1. 从源代码构建 TestNG

    you can download the source and build the distribution yourself:

  git clone git://github.com/cbeust/testng.git
  cd testng
  ./build-with-gradle