【问题标题】:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test)未能执行目标 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test)
【发布时间】:2020-03-30 08:09:42
【问题描述】:

我在使用 maven-surefire-plugin 3.0.0-M4 和使用 jdk1.8.0_222 (Ubuntu 18.0.4) 的 Maven 版本 3.6.3、3.6.0 和 3.3.9 时遇到了这个问题。我的 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>Expertus</groupId>
  <artifactId>Expertus</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>ExpertusONE_4.5</name>
  <description>ExpertusONE_4.5</description>
  <dependencies>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>3.141.59</version>
    </dependency>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>7.0.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>4.1.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml</artifactId>
      <version>4.1.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-failsafe-plugin</artifactId>
      <version>3.0.0-M4</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M4</version>
        <configuration>
          <useSystemClassLoader>false</useSystemClassLoader>
          <includes>
            <include>CreateOrganization.java</include>
          </includes>
          <suiteXmlFiles>
            <suiteXmlFile>/home/nivedab/Desktop/LocalCode/ExpertusONE_4.5/Learning_Suite.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <properties>
    <java.version>1.8.0_222</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
</project>

Jenkins输出如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test
  (default-test) on project Expertus: There are test failures.

【问题讨论】:

  • 请添加更多[错误]日志。

标签: java maven jenkins maven-surefire-plugin


【解决方案1】:
<suiteXmlFile>src/test/resources/${suiteXmlFile}.xml</suiteXmlFile>

任何名称都有 XML 文件,测试将运行

【讨论】:

    【解决方案2】:

    @尼维 首先,规则是不要阅读人们在谷歌上写的所有内容,因为他们也写了糟糕的页面。正确的做法是阅读 Apache Maven 的原始教程。

    您能否正确阅读本文档并查看页面https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html 上所有出现的单词“suiteXmlFiles”,这些配置参数在您的POM 中使用,不应组合。

    接下来使用绝对路径完全破坏了 Maven 的全部内容。您的文件 Learning_Suite.xml 应该是模块基本目录的真实路径。因此它是一个资源文件,配置在文档中看起来像这样&lt;file&gt;src/test/resources/suite.xml&lt;/file&gt;https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

    此外,1.8.0_222 版本是任何人都不应该使用的东西。这对每个 POM 来说已经足够且透明:

    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    

    【讨论】:

    • 解决办法是什么?不是你提议的吗?
    • 简单,将文件 Learning_Suite.xml 移动到 src/test/resources 然后配置如下 src /test/resources/Learning_Suite.xml.
    猜你喜欢
    • 2021-06-28
    • 2017-01-23
    • 2020-02-24
    • 2012-10-21
    • 2015-09-22
    • 1970-01-01
    • 2013-10-17
    • 1970-01-01
    • 2016-07-25
    相关资源
    最近更新 更多