java - Maven 不从命令行运行测试

标签 java maven cmd pom.xml

我正在尝试使用 mvn test 从 cmd 行运行一个项目。它显示构建成功但未运行任何测试,因为它显示测试运行:0。我已经尝试了 stackoverflow 中提供的所有建议,但仍然没有运行。请让我知道我在这里缺少什么。

我的 Maven 项目:

My maven project

命令行结果: cmd line results: 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>Winium</groupId>
  <artifactId>Test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Test</name>
  <url>http://maven.apache.org</url>
<properties>
    <junit.version>4.8.1</junit.version>
    <surefire.version>2.18</surefire.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
</properties>


<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.0.0-M4</version>
                </dependency>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.0.0-M4</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>


  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.1</version>
      <scope>test</scope>
    </dependency>   
    <dependency>
        <groupId>com.github.2gis.winium</groupId>
        <artifactId>winium-webdriver</artifactId>
        <version>0.1.0-1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.9</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.0.0-M4</version>
        <scope>test</scope>
    </dependency>
</dependencies> 
</project>

最佳答案

您正在混合使用 junit 4(在测试定义中)和 junit 5(在您的 pom.xml 中)。 如果可以为您使用 junit 4,请尝试使用以下(已编辑)版本的 pom.xml 文件;我已经删除了 surefire 插件配置——默认设置工作正常:

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

  <name>Test</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.github.2gis.winium</groupId>
      <artifactId>winium-webdriver</artifactId>
      <version>0.1.0-1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>3.9</version>
    </dependency>
  </dependencies>
</project>

关于java - Maven 不从命令行运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54863440/

相关文章:

java - 获取使用 USB 大容量存储或 USB 媒体设备将设备连接到台式机时显示的文件夹名称

java - 使用 Amazon S3 和 Cloudfront 智能缓存网页

java - 无法解析原型(prototype) org.glassfish.jersey.archetypes :jersey quickstart-webapp

java - 将 groupId 值包装在 Maven 依赖规范中

windows - 如何在Windows Batch中回显>不带引号的字符? [复制]

mysql - 无法使用cmd创建mysql数据库

应返回 9 个字符的随机字符串的 Java 函数

java - Spring Data Couchbase 对象 id

java - 对 AWS EC2/EBS 资源使用较长的 ID

windows - 批处理文件属性检查