[maven] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.

I have been trying from a couple of days to resolve the following error but I am unable to resolve it :(

My module's pom.xml file is:

<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>
<parent>
<artifactId>junitcategorizer</artifactId>
<groupId>com.topdesk.test.junitcategorizer</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>junitcategorizer.instrument</artifactId>
<name>JUnitCategorizer InstrumentationAgent</name>
<description>The agent used to instrument the called Java classes</description>
<dependencies>
<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm-commons</artifactId>
    <version>4.0</version>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
</dependency>
</dependencies>
<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
        </manifest>
        <manifestEntries>
            <Premain-Class>com.topdesk.junitcategorizer.instrument.InstrumentationAgent</Premain-Class>
            <Agent-Class>com.topdesk.junitcategorizer.instrument.InstrumentationAgent</Agent-Class>
            <Can-Redefine-Classes>true</Can-Redefine-Classes>
            <Can-Retransform-Classes>true</Can-Retransform-Classes>
            <Boot-Class-Path>${project.artifactId}-${project.version}.jar</Boot-Class-Path>
            <Can-Set-Native-Method-Prefix>true</Can-Set-Native-Method-Prefix>
        </manifestEntries>
      </archive>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.5</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration> 
          <artifactSet>
            <includes>
              <include>org.ow2.asm:*</include>
            </includes>
          </artifactSet>
          <relocations>
            <relocation>
              <pattern>org.objectweb.asm</pattern>
              <shadedPattern>org.shaded.asm</shadedPattern>
            </relocation>
          </relocations>
        </configuration>
      </execution>
    </executions>
  </plugin>
 </plugins>
 </build>
 </project>

I am getting the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
12:test (default-test) on project junitcategorizer.instrument: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Masters\thesis related papers and tools\junitcategorizer\junitcategorizer.instrument\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project junitcategorizer.instrument: There are test failures.

Please refer to D:\Masters\thesis related papers and tools\junitcategorizer\junitcategorizer.instrument\target\surefire-reports for the individual test results.

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
    Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

    Please refer to D:\Masters\thesis related papers and tools\junitcategorizer\junitcategorizer.instrument\target\surefire-reports for the individual test results.

    at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:83)
    at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary(SurefirePlugin.java:673)
    at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:647)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:137)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:98)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more
    [ERROR]
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.

I tried the following but did not help:

  1. mvn dependency::tree
  2. mvn clean install -U or Right-click on "project" Go to "Maven" >> "Update"

Please help me!

This question is related to maven maven-2

The answer is


Change the version number to 2.19.1 works for me :)

`<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <systemPropertyVariables>
            <xmlOutputDir>${project.build.directory}/surefire</xmlOutputDir>
        </systemPropertyVariables>
    </configuration>
</plugin>`

Was facing the same issue multiple times and I have 2 solutions:

Solution 1: Add surefire plugin reference to pom.xml. Watch that you have all nodes! In my IDEs auto import version was missing!!!

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M3</version>
    </plugin>
</plugins>

Solution 2: My IDE added wrong import to the start of the file.

IDE added

import org.junit.Test;

I had to replace it with

import org.junit.jupiter.api.Test;

Just add those below line in pom.xml file on the top of <modelversion> tag:

<repositories>
  <repository>
    <id>central</id>
    <name>Central Repository</name>
    <url>http://repo.maven.apache.org/maven2</url>
    <layout>default</layout>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
  </repository>
</repositories>

It worked for me with version 3.0.0-M1.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M1</version>
</plugin>

You might need to run it with sudo.


I have the same problem and try almost all these suggestions and another options but nothing works for my case.

So I had run verbose command: (mvn install -X) and saw the problem with Jacoco lib, and finally found this answer that works for me.

Change the Jacoco lib version in my pom file.

<groupId>org.jacoco</groupId>
     <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>

I just adjust the cucumber version, because I had a JUnit dependency in a low version compared with the other version of cucumber in my pom file.


<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>6.9.0</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-picocontainer</artifactId>
                <version>6.9.0</version>
                <scope>test</scope>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-junit</artifactId>
                <version>6.9.0</version>
                <scope>test</scope>
            </dependency>

Here is the simplest way to resolve this error:

1) Go to your pom.xml file path

2) And edit the pom.xml like:

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12</version>
    </plugin>
</plugins>

3) Save the file That's it.


surefire plugins version might be one of the reasons. For me following dependency worked. Please try:

    <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
</dependency>

Try this it works!

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                <testFailureIgnore>true</testFailureIgnore>
                <shutdown>kill</shutdown> <!-- Use it if required-->
                </configuration>
            </plugin>

This solved my issue. It was 2.10 in my POM, just updated to 2.19.1 and refresh the POM

Add to your pom :

 <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
        </plugin>
  </plugins>

In your error code he didn't find surefire plugin so add it


If you are using ubantu then try to run MVN with sudo. I got same error for

mvn -Dtest=PerfLatency#latencyTest test -X 

But

sudo mvn -Dtest=PerfLatency#latencyTest test -X 

Solved my problem


after a few days of wondering, my solution was that I forgot to use @Test annotation before the @BeforeEach


HI All can you try adding the below in your POM and then use mvn clean compile and then mvn install.

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

The problem is not in your dependencies.... you should open detail error on this path

Please refer to D:\Masters\thesis related papers and tools\junitcategorizer\junitcategorizer.instrument\target\surefire-reports for the individual test results.

the detail error's in there, maybe your service class or serviceImpl class or something missing like @anotation or else... i got error same with you,...u should try


This is a kind of test failure.@SpringBootApplication annotation contains these configurations.

1) @Configuration

2) @ComponentScan

3) @EnableAutoConfiguration

@EnableAutoConfiguration is the reason for this error. This will try to automatically configure application according to dependencies in your pom.xml

As a example when you have spring-data-jpa dependency in pom it will try to add configuration to application by looking at application.properties file for data source. So you need add data source to solve that.

For MySQL :

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost/lahiru
spring.datasource.username=root
spring.datasource.password=

Or

You could hide this by skipping testing.

mvn install -DskipTests

For more details.


I was facing the same kind of issue, your version numbers in the dependency of Selenium, TestNG, Junit should the same that you have used in your project. For example, in your project you are using the Selenium version 3.8. This version number should be mentioned in the dependency.

 <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.0.0-beta1</version>
    <scope>test</scope>
</dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>3.8.1</version>
    </dependency>       
    <dependency>                
      <groupId>org.testng</groupId>                             
      <artifactId>testng</artifactId>                               
      <version>6.8</version>                                
      <scope>test</scope>                                       
    </dependency>   
  </dependencies>

I get exactly the same stacktrace when tests fail. More to the top you should see messages identfying the failing test classes. Or go to

D:\Masters\thesis related papers and tools\junitcategorizer\junitcategorizer.instrument\target\surefire-reports

and have a look at the failure reports. Fix the problems and your build is ok.

Good news : Your poms seem to be ok, Maven can compile and execute tests.


3 years already, but the same thing happened to me and I wanted to contribute with my case. Using the @nikk solution I got better results, but other errors still appeared, although yes, I was allowed to package.

However, my task was to implement the code of a co-worker on the server and it did not happen to him in his test environment, so I decided to investigate a little more since the code was functional and did not correspond to me touching anything .

In the end it turned out that his application inserted mysql tables into a database that did not exist. The solution was as easy as creating such a database and the error disappeared.


This is what solves the problem:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <testFailureIgnore>true</testFailureIgnore>
    </configuration>
</plugin>

from Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test


Check your test files. You must clear all test files error on your project and try Clean and build.


This issue could be related to the already busy port. Surefire run on 5005 port. So you need to make sure that this port is free. If not change it or kill the process. This happens in Intellij some time.


That worked for me,

Right Click on project -> "Run as Maven Test". This will automatically download the missing plugins and than Right Click on project ->"Update Maven project" it removes the error.


This error is brought up for many different reasons so everyone has a different solution. However, your own webapp should hold the answer for it.

You can look it up in

/module_with_failure/target/surefire-reports/*.txt


This happens when Maven tries to run your test cases while building the jar. You can simply skip running the test cases by adding -DskipTests at the end of your maven command.

Ex: mvn clean install -DskipTests or mvn clean package -DskipTests


If there are test failures just skip them with

mvn install -DskipTests

but i strongly recomend fixing your test first.


try in cmd: mvn clean install -Dskiptests=true

that'll skip all unit test. Might be It'll work fine for you.


I was facing the same problem and how i resolved see below steps or Image:

  1. Clicked on Windows menu item of eclipse
  2. Clicked on preferences
  3. select Installed JREs
  4. Add your installed jdk's path(JRE home: C:\Program Files\Java\jdk1.8.0_201\jre`)
  5. Add JRE name: jdk1.8.0_201
  6. Clicked on Finish
  7. Apply changes and close

enter image description here


It may be better to set the surefire-plugin version in the parent pom, otherwise including it as a dependency will override any configuration (includes file patterns etc) that may be inherited, e.g. from Spring Boots spring-boot-starter-test pom using pluginManagement

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Make sure the name of the class created in the package is something like somethingTest.java Maven only picks the java files ending with Test notation.

I was getting the same error and resolving the names of all my classes by adding 'Test' at the end made it work.


Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException

Examples related to maven-2

Maven:Non-resolvable parent POM and 'parent.relativePath' points at wrong local POM Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project. Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved Maven Error: Could not find or load main class MAVEN_HOME, MVN_HOME or M2_HOME Where is my m2 folder on Mac OS X Mavericks Maven won't run my Project : Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 'mvn' is not recognized as an internal or external command, operable program or batch file SLF4J: Class path contains multiple SLF4J bindings Create local maven repository