【问题标题】:how to run maven project testng.xml from the command prompt如何从命令提示符运行 maven 项目 testng.xml
【发布时间】:2015-11-19 18:26:44
【问题描述】:

我正在使用 linux 机器(ubuntu 14)。我的项目是带有 testng 框架的 Maven 项目。在这里,我尝试从命令提示符运行 testng.xml,以便我可以在 jenkins 中进行配置。

project location : /home/subhash/workspace/myproject
class path is  : /home/subhash/workspace/myproject/bin
testng jar locattion is: /home/subhash/.m2/repository/org/testng/testng/6.9.4/testng-6.9.4.jar"

suite location is : /home/subhash/workspace/suites/src/test/resources/testng.xml

hence i executed the following command from command prompt from the location.
/home/subhash/workspace/myproject/bin$ 

$ java -cp ".:../lib/*:/home/subhash/.m2/repository/org/testng/testng/6.9.4/testng-6.9.4.jar" org.testng.TestNG /home/subhash/workspace/suites/src/test/resources/testng.xml

我得到了以下异常:

Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException

因此我在 pom.xml 中添加了如下依赖项。

<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>

构建它。它是成功的。 我再次运行上述命令来运行 testng.xml,但仍然显示相同的异常。

请帮助我解决这个问题。

提前致谢。 子哈希。

【问题讨论】:

    标签: java maven jenkins testng


    【解决方案1】:

    看看这个问题:Suddenly can't run TestNG tests from ant ([testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException)

    好像是同一个问题

    希望有所帮助!

    更新

    尝试在 cp java 参数中添加 m2 中的 'beust' jar 路径。

    【讨论】:

    • 嗨弗朗西斯,谢谢你的帖子。正如帖子中建议的那样,我已经完成了。我已经用最新的替换了我的 testng.jar 文件并尝试再次运行 testng.xml 文件仍然显示异常,仍然显示以下异常。线程“main”中的异常 java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException at java.lang.Class.getDeclaredMethods0(Native Method)
    • 嗨,Subash,您是否尝试将“beust”jar 路径添加到 -cp java 参数?以与添加 testng jar 路径相同的方式进行操作
    【解决方案2】:

    使用 mvn test 而不是 testng jar 运行测试会更容易。 在 pom 中设置 mvn surefire 插件并使用 mvn test -DsuiteXmlFile=src/test/resources/yourxml.xml 运行

    【讨论】:

    • 我尝试添加这个插件并运行 maven 测试。显示异常。无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.19:test (default-test) on test-suite: Execution default-test of goal org.apache.maven.plugins:maven -surefire-plugin:2.19:测试失败:分叉进程中出现错误 [错误] org.apache.maven.surefire.testset.TestSetFailedException:套件文件 /home/subhash/workspace/test-suite/test_suite_main.xml 是在 org.apache.maven.surefire.testng.TestNGXmlTestSuite.locateTestSets(TestNGXmlTestSuite.java:115) 处不是有效文件 [错误]
    • 它说套件文件无效。这条路径可以从你的 Maven 运行的地方访问吗?
    • 只要把文件放到你的项目中,使用src/test/resources/testng.xml..不需要给出绝对路径
    猜你喜欢
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 2023-04-04
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    相关资源
    最近更新 更多