【问题标题】:How to run a Maven project containing junit test class in windows command line?如何在 Windows 命令行中运行包含 junit 测试类的 Maven 项目?
【发布时间】:2020-05-12 13:27:17
【问题描述】:

我是 MAVEN 和 Junit 的新手。我正在尝试在命令行中运行一个包含 junit 测试和黄瓜功能文件的 maven 项目。 它显示“构建成功”,但也显示“无需编译”。它是一个使用 Selenium 和黄瓜功能文件的网络自动化代码。有人可以帮我在 windows 的命令行中运行它。这是 POM 文件。(项目没有 Main 类。)

   <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>BFL</groupId>
  <artifactId>Web_Automation</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Web_Automation</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>3.8.1</version>        
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>        
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.35.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>   

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm-deps</artifactId>
        <version>1.0.5</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.vimalselvam</groupId>
        <artifactId>cucumber-extentsreport</artifactId>
        <version>3.0.2</version>
    </dependency>

  </dependencies>
  <build>
     <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.14.1</version>
          <configuration>
            <mainClass>test_runner.WEBRUNNER</mainClass>        
            <systemPropertyVariables>
             <!-- <retryCount>${retryCount}</retryCount> -->
              <!-- <accountBrowser>${myaccountBrowser}</accountBrowser>
              <searchBrowser>${searchBrowser}</searchBrowser>
              <pdpBrowser>${pdpBrowser}</pdpBrowser>
              <browseBrowser>${browseBrowser}</browseBrowser>
              <cartBrowser>${cartBrowser}</cartBrowser>
              <globalNavBrowser>${globalNavBrowser}</globalNavBrowser>
              <homeBrowser>${homeBrowser}</homeBrowser>-->
            </systemPropertyVariables>
        </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

【问题讨论】:

  • 到目前为止你有什么尝试?
  • 在找到包含POM文件和其他代码包的项目目录后,我只是运行了“mvn test”命令。
  • 在构建过程中你应该有一些 WARNING ....
  • @khmarbaise 感谢您的回复。是的..我收到警告“工件 org.apache.commons:common-io:jar :1.3.2 已重新定位到 common-io:commons-io :jar:13.2"
  • 这意味着您使用了错误的依赖项。首先,这需要修复。除了使用 JUnit 3 ...我怀疑这是否正确....

标签: eclipse maven selenium junit


【解决方案1】:

我建议删除maven-surefire-plugin 的插件,并在junitcucumber-junit 依赖项中添加test 的作用域,如下所述

<dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>  
    <scope>test</scope>      
</dependency>

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>        
</dependency>

现在在命令行中找到项目的根目录并尝试以下命令运行

mvn test

【讨论】:

  • 没有对maven-surefire-plugin 的依赖,它在pluginManagement 中定义,这与依赖不同。
  • 我的错误。我的意思是插件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-16
  • 2014-01-05
相关资源
最近更新 更多