从 Ant 运行 TestNG 套件时出错:“无法在类路径中找到类”

发布于 2024-09-30 21:08:12 字数 1488 浏览 0 评论 0原文

我创建了一套 TestNG 测试,尝试使用 Selenium Grid 从 Ant 任务运行. 我尝试在 Ant 中设置类路径,包括 TestNG jar 和其他一些必需的 jar(测试是 Selenium 测试)。这是从 Selenium Grid 演示中稍微修改的,以反映我的环境中的位置。

<path id="runtime.classpath">
   <pathelement path="${java.class.path}/" />
    <fileset dir="C:\Tools\selenium-grid-1.0.8\vendor">
        <include name="selenium-java-client-driver-${selenium.version}.jar"/>
       <include name="testng-5.7-jdk15.jar"/>
        <include name="commons-logging-1.0.4.jar"/>
    </fileset>
    <fileset dir="${test.location}">
        <include name="**/*.java" />
    </fileset>
    <pathelement location="${grid.location}/lib/selenium-grid-tools-standalone-${grid.version}.jar" />
</path>

TestNG 启动,但立即失败并出现错误:

     [java] ===============================================
     [java] Selenium Tests
     [java] Total tests run: 0, Failures: 0, Skips: 0
     [java] ===============================================
     [java]
     [java] [ERROR]:
     [java] Cannot find class in classpath: TestName

test.location 当前指向测试的 src 文件夹。更改 test.location 以包含 bin 目录,并将 name 属性更改为 **/*.class没有什么区别;错误是一样的。

我可以从 Eclipse 插件成功运行这个套件,所以我知道测试套件文件没问题。我正在努力让它在 Ant 中运行,以确保 Selenium Grid 实际上将测试正确分发到 Selenium 远程控制。

I've created a suite of TestNG tests that I'm attempting to run from an Ant task using Selenium Grid. I've tried to set the classpath in Ant, including the TestNG jar and some other required jars (the tests are Selenium tests). This is modified slightly from the Selenium Grid demo to reflect locations in my environment.

<path id="runtime.classpath">
   <pathelement path="${java.class.path}/" />
    <fileset dir="C:\Tools\selenium-grid-1.0.8\vendor">
        <include name="selenium-java-client-driver-${selenium.version}.jar"/>
       <include name="testng-5.7-jdk15.jar"/>
        <include name="commons-logging-1.0.4.jar"/>
    </fileset>
    <fileset dir="${test.location}">
        <include name="**/*.java" />
    </fileset>
    <pathelement location="${grid.location}/lib/selenium-grid-tools-standalone-${grid.version}.jar" />
</path>

TestNG starts, but immediately fails with an error:

     [java] ===============================================
     [java] Selenium Tests
     [java] Total tests run: 0, Failures: 0, Skips: 0
     [java] ===============================================
     [java]
     [java] [ERROR]:
     [java] Cannot find class in classpath: TestName

test.location is currently pointing to the src folder for the tests. Changing the test.location to contain the bin directory and changing the name attribute to **/*.class doesn't make a difference; the error is the same.

I can run this suite successfully from the Eclipse plugin, so I know the test suite file is ok. I'm working to get it running in Ant to ensure that Selenium Grid actually is distributing the tests properly to the Selenium Remote Controls.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

錯遇了你 2024-10-07 21:08:12

不要将类路径设置为指向各个类文件,而是将其设置为指向父目录。

而不是

<fileset dir="${test.location}">
    <include name="**/*.java" />
</fileset>

尝试

<pathelement path="${test.location}" />

(尽管您可能需要将其更改为指向 bin 目录,而不是 src 目录)。

Rather than setting the classpath to point at the individual class files, set it to point at the parent directory.

Instead of

<fileset dir="${test.location}">
    <include name="**/*.java" />
</fileset>

try

<pathelement path="${test.location}" />

(although you may need to change this to point at the bin dir, not the src dir).

凹づ凸ル 2024-10-07 21:08:12

我在不止一个实例上遇到了同样的错误。在探索 Eclipse 寻求解决方案时,我偶然进入了“标记”窗口(主菜单 -> Windows -> 显示视图 -> 标记),该窗口表示我的项目(proj1,我使用 Testng 启动)缺少所需的库,该库情况就是如此。

我使用外部 java 项目 (ext_proj),将其作为外部 jar 文件附加到该项目的构建路径 proj1 中(通过将其指向位于 ext_proj 目录中的 ext_proj.jar)。我不小心清理了 (ext_proj),从而清除了其中的 ext_proj.jar。我在控制台中看不到上述错误的确切原因,但只能在我上面指出的“标记”窗口中看到。

一旦我在 proj1 中提供了这个 ext_proj.jar,这个错误就消失了。

i was caught with the same error on more than one instance. While exploring eclipse for solution, i stumbled into the Markers window (Main menu ->Windows -> Show View -> Markers) which said that my project (proj1, which i launched using Testng) is missing a required library, which was the case.

I was using an external java project (ext_proj) by attaching it as an external jar file in the build path of this project, proj1 (by pointing it to the ext_proj.jar which resides in ext_proj directory). I accidentally cleaned the (ext_proj) which wiped out the ext_proj.jar in it. I could not see the exact cause of this above error in the Console but only in the Markers window as i pointed above.

Once i made this ext_proj.jar available in proj1 this error was gone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文