无法在项目上执行目标org.apache.maven.plugins:maven-surefire-plugin:2.12:test(default-test).

Sri*_*inu 28 maven-2 maven

我已经尝试了几天来解决以下错误,但我无法解决它:(

我的模块的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>
<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>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

[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.
Run Code Online (Sandbox Code Playgroud)

我尝试了以下但没有帮助:

  1. mvn依赖:: tree
  2. mvn clean install -U或右键单击"project"转到"Maven">>"Update"

请帮我!

Hoh*_*eim 28

加入你的pom:

 <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
        </plugin>
  </plugins>
Run Code Online (Sandbox Code Playgroud)

在你的错误代码中,他没有找到,surefire plugin所以添加它

  • &lt;插件&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt; &lt;版本&gt;2.19.1&lt;/版本&gt; &lt;配置&gt; &lt;testFailureIgnore&gt;true&lt;/testFailureIgnore&gt; &lt;/配置&gt; &lt;/插件&gt; (2认同)
  • 就我而言,我必须从 2.22.2 返回到 2.22.1 (我仍然不明白为什么,但它有效:S) (2认同)

小智 17

当 Maven 在构建 jar 时尝试运行您的测试用例时,就会发生这种情况。您可以通过-DskipTests在 Maven 命令的末尾添加来简单地跳过运行测试用例。

例如:mvn clean install -DskipTestsmvn clean package -DskipTests


nik*_*ikk 11

这就是解决问题的方法:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <testFailureIgnore>true</testFailureIgnore>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

失败执行目标org.apache.maven.plugins:maven-surefire-plugin:2.10:test


elr*_*ado 9

多次面临同样的问题,我有两个解决方案:

解决方案1: 在pom.xml中添加surefire插件引用。注意您拥有所有节点!在我的 IDE 中缺少自动导入版本!!!

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M3</version>
    </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

解决方案 2:我的 IDE 在文件开头添加了错误的导入。

添加了 IDE

import org.junit.Test;
Run Code Online (Sandbox Code Playgroud)

我不得不用

import org.junit.jupiter.api.Test;
Run Code Online (Sandbox Code Playgroud)

  • 升级 maven-surefire-plugin 后,这对我来说非常有效。 (2认同)

Lah*_*age 7

这是一种测试失败。@SpringBootApplication批注包含这些配置。

1)@配置

2)@ComponentScan

3)@EnableAutoConfiguration

@EnableAutoConfiguration是此错误的原因。这将尝试根据pom.xml中的依赖关系自动配置应用程序

例如,当您在pom中具有spring-data-jpa依赖项时,它将通过查看数据源的application.properties文件来尝试向应用程序添加配置。因此,您需要添加数据源来解决该问题。

对于MySQL:

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost/lahiru
spring.datasource.username=root
spring.datasource.password=
Run Code Online (Sandbox Code Playgroud)

要么

您可以通过跳过测试来隐藏它。

mvn install -DskipTests
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息


小智 6

它适用于3.0.0-M1版本。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M1</version>
</plugin>
Run Code Online (Sandbox Code Playgroud)

您可能需要使用sudo运行它。


小智 6

试试这个,行得通!

<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>
Run Code Online (Sandbox Code Playgroud)

  • &lt;testFailureIgnore&gt;true&lt;/testFailureIgnore&gt; 设置为true只是忽略失败,并不能帮助停止失败 (6认同)