Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java TestNgeException:在类路径中找不到类_Java_Eclipse_Maven_Classpath_Testng - Fatal编程技术网

Java TestNgeException:在类路径中找不到类

Java TestNgeException:在类路径中找不到类,java,eclipse,maven,classpath,testng,Java,Eclipse,Maven,Classpath,Testng,团队 我知道这是一个很受欢迎的问题,但我一直在研究这两天没有运气。当我通过testng.xml执行测试套件时,出现以下错误: TestNgeException:在类路径中找不到类: (packageName.className) 我正在为Java开发人员使用EclipseIDE 版本:Mars.1版(4.5.1) 构建id:20150924-1200 还有马文 这是我的pom文件: 4.0.0 变薄 变薄 0.0.1-快照 罐子 变薄 http://maven.apache.org UTF-8

团队

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

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

我正在为Java开发人员使用EclipseIDE

版本:Mars.1版(4.5.1)

构建id:20150924-1200

还有马文

这是我的pom文件:

4.0.0
变薄
变薄
0.0.1-快照
罐子
变薄
http://maven.apache.org
UTF-8
朱尼特
朱尼特
4.8.1
测试
org.seleniumhq.selenium
硒爪哇
2.48.2
org.testng
testng
6.1.1
测试
org.apache.maven.plugins
maven编译器插件
3
1.8
1.8
org.apache.maven.plugins
maven surefire插件
2.18.1
src/main/resources


我已经通过eclipse清理了项目,更新了maven,运行了maven清理和构建,但没有任何成功。我甚至确保我的系统库使用了正确的JavaJDK1.8。请告知我是否还需要执行其他操作?

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


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

如果您试图通过testng.xml(我想是通过testng插件)运行测试,为什么要提供pom文件?顺便说一句,它是否仅通过maven(mvn测试)按预期工作?您也应该向surefire提供testng.xml文件(参见文档)@juherr是的,它作为maven工作,您指的是什么文档?surefire的一个:。您还应该提供test.xml文件。
<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>