Intellij-无法在项目***上执行目标org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test(default-test):存在测试失败

时间:2020-04-23 12:47:05

标签: java maven junit5 maven-surefire-plugin

我有一个Java Maven项目,其中我正在使用JUnit Juniper进行单元测试,而在构建项目时却出现错误,好像我从本地构建相同的项目一样,它工作得很好。

这是Intellij的问题吗?

在Intellij中构建我的Maven项目时遇到以下问题,而从本地构建时不会出现此问题。

  • Intellij 2019.1.1
  • Maven版本#3.3.9
  • JDK#1.8

错误

Error Messages # [ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project ImplementJunit: There are test failures.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was cmd.exe /X /C ""C:\Program Files\Java\jdk1.8.0_221\jre\bin\java" -jar C:\Users\mnayak6\AppData\Local\Temp\surefire2741322585113384847\surefirebooter6121148917405790398.jar C:\Users\mnayak6\AppData\Local\Temp\surefire2741322585113384847 2020-04-23T15-08-00_156-jvmRun1 surefire3485996048802854818tmp surefire_08080424484537241935tmp"
[ERROR] Process Exit Code: 0
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was cmd.exe /X /C ""C:\Program Files\Java\jdk1.8.0_221\jre\bin\java" -jar C:\Users\mnayak6\AppData\Local\Temp\surefire2741322585113384847\surefirebooter6121148917405790398.jar C:\Users\mnayak6\AppData\Local\Temp\surefire2741322585113384847 2020-04-23T15-08-00_156-jvmRun1 surefire3485996048802854818tmp surefire_08080424484537241935tmp"
[ERROR] Process Exit Code: 0
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:669)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:282)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:245)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1183)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1011)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:857)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR] at org.codehaus.classworlds.Launcher.main(Launcher.java:47)

POM.XML

<properties>
        <!-- https://maven.apache.org/general.html#encoding-warning -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
            <!-- ... -->
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>5.4.0 </version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>5.4.0</version>
                <scope>test</scope>
            </dependency>
            <!-- ... -->

        <!-- ... -->
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.2.0</version>
        </dependency>

    </dependencies>

    <build>

        <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
                <execution>
                    <id>test-compile</id>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <dependencies>
                    <dependency>
                        <groupId>org.junit.platform</groupId>
                        <artifactId>junit-platform-surefire-provider</artifactId>
                        <version>1.2.0</version>
                    </dependency>
                </dependencies>
            </plugin>

        </plugins>

    </build>

测试类:

@Test
public void testGetMidDate()
{
    ImplementJunit implementJunit = new ImplementJunit();

    System.out.println("calling testGetMidDate() ");

    String date = implementJunit.getMidDate("20200101", "20200103");

    String ExpectedDate = "20200102";
    assertEquals(ExpectedDate,date);
}

1 个答案:

答案 0 :(得分:0)

我在Eclipse / Maven / JDK1.8 / SureFire插件上转载了此问题。

enter image description here

分辨率:-

我更正了所有正在运行的测试后,问题解决了。一旦所有测试通过,错误就消失了。 尽管这并没有指定根本原因和问题的确切解决方案,但我认为与surefire插件的默认设置有关的是在任何测试失败后跳过测试

enter image description here