Java – Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test)

javaJenkinsmavenmaven-surefire-plugin

I am facing this issue with maven-surefire-plugin 3.0.0-M4 and Maven versions 3.6.3, 3.6.0 and 3.3.9 with jdk1.8.0_222 (Ubuntu 18.0.4). My pom.xml is as follows:

<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 output is as follows:

[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.

Best Answer

@Nivi First of all, the rule is not to read all what the people write on the Google because they also write bad pages. The right thing is to read the original tutorial from the Apache Maven.

Can you read this documentation properly and see all occurences of the word "suiteXmlFiles" on the page https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html that these configuration parameters, you have used in your POM, should not be combined.

Next that you use absolute paths completely breaks all what the Maven is about. Your file Learning_Suite.xml should be a realtive path to module's base dir. Therefore it is a resource file and the configuration looks like this <file>src/test/resources/suite.xml</file> in the documentation: https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

Additionally, the version 1.8.0_222 is something what nobody should use. This is enough and transparent for every POM:

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