簡體   English   中英

TestNGException:在類路徑中找不到 class

[英]TestNGException: Cannot find class in classpath

團隊,

我知道這是一個很受歡迎的問題,但我一直在研究這 2 天,但沒有成功。 當我通過testng.xml執行我的測試套件時,出現以下錯誤:

TestNGException:在類路徑中找不到 class:(packageName.className)

我正在為 Java 開發人員使用 Eclipse IDE

版本: Mars.1 發布 (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。 請告知是否還有其他我需要做的事情?

您需要在類路徑中包含 packageName.className 的 .class(如錯誤所述)。 因此,當您通過命令行運行 .xml 文件時,它應該類似於java -cp %CLASSPATH%;path/to/packageName.className.class org.testng.TestNG path/to/testng.xml

根據您的 class 路徑中已經存在或不存在的內容,您還需要包含庫的路徑。 因為輸入起來可能很麻煩,所以我強烈建議根據您的操作系統將其保存為 shell 腳本或批處理文件。

我遇到了同樣的錯誤。 我只是通過執行此步驟解決了問題。

再次轉換TestNG

右鍵單擊項目 --> TestNG --> 轉換為 TestNG。

刷新您的項目(右鍵單擊項目 --> 刷新)

現在再次從 testng.xml 運行測試(右鍵單擊 testng.xml --> run as --> TestNgSuite)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM