【问题标题】:TestNGException: Cannot find class in classpathTestNGException:在类路径中找不到类
【发布时间】:2015-10-14 14:22:39
【问题描述】:

团队,

我知道这是一个受欢迎的问题,但我一直在研究这 2 天,但没有运气。当我通过testng.xml 执行我的测试套件时,我收到以下错误:

TestNGException:在类路径中找不到类: (packageName.className)

我正在为 Java 开发人员使用 Eclipse IDE

版本: Mars.1 Release (4.5.1)

版本号: 20150924-1200

还有 Maven。

这是我的 pom 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ASWRegression</groupId>
<artifactId>ASWRegression</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ASWRegression</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>


    <dependency>

        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.48.2</version>

    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.1.1</version>
        <scope>test</scope>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

         <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.18.1</version>
    </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>

</build>

我已经通过 eclipse 清理了项目,更新了 maven 运行 maven 清理和构建,但没有任何成功。我什至确保我的系统库正在提取正确的 java jdk 1.8。请问我还有什么需要做的吗?

【问题讨论】:

  • 如果您尝试通过 testng.xml(我想是通过 TestNG 插件)运行测试,为什么要提供您的 pom 文件?顺便说一句,它仅通过 maven(mvn 测试)按预期工作?您也应该将 testng.xml 文件提供给 surefire(参见文档)
  • @juherr 是的,它像 maven 一样工作,你指的是什么文档?
  • Surefire 的一个:maven.apache.org/surefire/maven-surefire-plugin/…。你也应该提供你的 test.xml 文件。

标签: java eclipse maven classpath testng


【解决方案1】:

您需要在类路径中包含 packageName.className 的 .class(如错误所示)。因此,当您通过命令行运行 .xml 文件时,它应该类似于 java -cp %CLASSPATH%;path/to/packageName.className.class org.testng.TestNG path/to/testng.xml

根据您的类路径中已有或尚未包含的内容,您还需要包含库的路径。因为这可能是一件苦差事,我强烈建议根据您的操作系统将其保存为 shell 脚本或批处理文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多