如何在Maven项目的类路径中设置TestNG?

时间:2015-03-26 09:38:45

标签: java eclipse maven classpath testng

为了在命令行上运行TestNG测试,我必须在classpath中设置TestNG。为此,我经历了 -

Unable to execute TestNG Suite file via command line

Getting error Could not find or load main class org.testng.TestNG

表示如果testng.jar在项目的lib文件夹中,则在类路径中设置路径直到lib文件夹(如 - C:\Workspace\projectname\lib\*)。

但在我的情况下,我正在使用Maven项目,因此没有lib文件夹来放置jar。在这种情况下,如何在类路径中设置TestNG?因此在命令行上运行TestNG测试。

3 个答案:

答案 0 :(得分:0)

如果您正在使用maven,您是否尝试使用命令

运行测试
 mvn test -DsuiteXmlFile=<xml file>

答案 1 :(得分:0)

mvn test -D <suiteXmlFile.xml>

为调试日志添加'-X',此命令效果很好。

真的推荐。

答案 2 :(得分:0)

我和上面有同样的问题

Below is pom.xml file

<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>org.project</groupId>
  <artifactId>WeWalkThru</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.3</version>
    <scope>test</scope>
</dependency>

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>



  </dependencies>
</project>
相关问题