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

MavenMaven 2

Maven Problem Overview


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!

Maven Solutions


Solution 1 - Maven

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

Solution 2 - Maven

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 https://stackoverflow.com/questions/13170860/failed-to-execute-goal-org-apache-maven-pluginsmaven-surefire-plugin2-10test/41666587#41666587

Solution 3 - Maven

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

Solution 4 - Maven

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;

Solution 5 - Maven

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>

Solution 6 - Maven

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.

Solution 7 - Maven

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.

Solution 8 - Maven

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.

Solution 9 - Maven

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>
  1. Save the file That's it.

Solution 10 - Maven

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>

Solution 11 - Maven

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

Solution 12 - Maven

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

Solution 13 - Maven

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.

Solution 14 - Maven

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

Solution 15 - Maven

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>`

Solution 16 - Maven

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

Solution 17 - Maven

My situation might be a bit different - but I was using Java 11 instead of Java 8.

Solution 18 - Maven

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>

Solution 19 - Maven

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.

Solution 20 - Maven

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.

Solution 21 - Maven

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

Solution 22 - Maven

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>

Solution 23 - Maven

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>

Solution 24 - Maven

I have faced the same problem and try all the method mentioned above. Then I identified that the problem is in the pom file.

so if you have given TestNG.xml in your pom file. Then, Perhaps the location of the TestNG.xml file is not correct.

By writing above command it will search the file in the root directory. If your TestNG.xml file is present somewhere else other then root directory then give that path or else copy the whole path of the TestNG.xml file from the server and paste it.

In my case I have done like below: /home/ubuntu/TestNG.xml

and the problem resolved.

Solution 25 - Maven

Karate is case sensitive so making sure your file and folder name and also package reference in Test runner file.

Solution 26 - Maven

After trying for some time I was able to fix the issue so thought of posting as it can be helpful to someone in the future:

  1. It has nothing to do with your pom.xml file and does not require any additional library or plugins.

  2. You are getting the path of the file where failing reports are present. Something like this:

[ERROR] Please refer to /Users/{username}/{folderPath}/{projectName}/target/surefire-reports for the individual test results.
  1. Click on that path and go to the folder. Within the folder search for the file testing-failed.xml file and open it in any of the editors.

  2. You will be able to see the Class/Test which is failing. Something like this:

<class name="PackageName.ClassName">
  1. Go to that file in your IDE and try to run it. If it's failing then fix it and try to run the mvn clean install again.

This should fix the issue, at least for me it worked.

Solution 27 - Maven

If you skip test by command or Intellij maven tool it will work, but its not solution. For solve the solution simply add following plugin.

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

Solution 28 - Maven

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>

Solution 29 - Maven

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>

Solution 30 - Maven

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>

Solution 31 - Maven

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

Solution 32 - Maven

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.

Solution 33 - Maven

If there are test failures just skip them with

mvn install -DskipTests

but i strongly recomend fixing your test first.

Solution 34 - Maven

try in cmd: mvn clean install -Dskiptests=true

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSrinuView Question on Stackoverflow
Solution 1 - MavenHohenheimView Answer on Stackoverflow
Solution 2 - MavennikkView Answer on Stackoverflow
Solution 3 - MavenTharun KumarView Answer on Stackoverflow
Solution 4 - MavenelradoView Answer on Stackoverflow
Solution 5 - MavenXpertView Answer on Stackoverflow
Solution 6 - MavensetnosetView Answer on Stackoverflow
Solution 7 - MavenLahiru GamageView Answer on Stackoverflow
Solution 8 - MavenStefan Isele - prefabware.comView Answer on Stackoverflow
Solution 9 - Mavennk07View Answer on Stackoverflow
Solution 10 - MavenVarjãoView Answer on Stackoverflow
Solution 11 - MavenFerhat KOÇERView Answer on Stackoverflow
Solution 12 - MavenShyamView Answer on Stackoverflow
Solution 13 - MavenvikramView Answer on Stackoverflow
Solution 14 - MavenAjit BhavleView Answer on Stackoverflow
Solution 15 - MavenRaja P.B.View Answer on Stackoverflow
Solution 16 - MavenSvetoslav StoyanovView Answer on Stackoverflow
Solution 17 - MavenBo NiView Answer on Stackoverflow
Solution 18 - Mavenmudassar munirView Answer on Stackoverflow
Solution 19 - MavenAloView Answer on Stackoverflow
Solution 20 - MavenAbubakarView Answer on Stackoverflow
Solution 21 - MavennicKarahtarView Answer on Stackoverflow
Solution 22 - MavenTom ChamberlainView Answer on Stackoverflow
Solution 23 - Maven0NewenView Answer on Stackoverflow
Solution 24 - MavenHarsh Wardhan GuptaView Answer on Stackoverflow
Solution 25 - MavenMajedurView Answer on Stackoverflow
Solution 26 - MavenBATMAN_2008View Answer on Stackoverflow
Solution 27 - MavenTohid MakariView Answer on Stackoverflow
Solution 28 - MavennarayanView Answer on Stackoverflow
Solution 29 - MavenPradeep KumarView Answer on Stackoverflow
Solution 30 - Mavenhabin prasadView Answer on Stackoverflow
Solution 31 - Mavenvadly molebilaView Answer on Stackoverflow
Solution 32 - MavenicebergView Answer on Stackoverflow
Solution 33 - MavenEric Miguel Mercado NavarroView Answer on Stackoverflow
Solution 34 - MavenMohit SinghView Answer on Stackoverflow