【问题标题】:How to set TestNG in classpath in Maven project?如何在 Maven 项目的类路径中设置 TestNG?
【发布时间】:2015-05-30 06:33:01
【问题描述】:

为了在命令行上运行 TestNG 测试,我必须在类路径中设置 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 测试。

【问题讨论】:

  • 在您的 pom 文件中添加 TestNG 作为依赖项。不要开始使用像 lib 文件夹这样的残缺的东西。
  • 我已经添加了它,但是当我在命令行上点击java org.testng.TestNG testng.xml 时,它会导致错误 - Error: Could not find or load main class org.testng.TestNG
  • 你能发布你的 POM 吗?

标签: java eclipse maven classpath testng


【解决方案1】:

如果您使用的是 maven ,您是否尝试过使用命令运行测试

 mvn test -DsuiteXmlFile=<xml file>

【讨论】:

    【解决方案2】:
    mvn test -D <suiteXmlFile.xml>
    

    为调试日志添加'-X',此命令运行良好。

    真心推荐。

    【讨论】:

      【解决方案3】:

      我遇到了和上面一样的问题

      下面是 pom.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>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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-05-15
        • 1970-01-01
        • 1970-01-01
        • 2023-03-04
        • 2018-11-17
        • 2012-07-21
        • 1970-01-01
        相关资源
        最近更新 更多