Maven Surefire:启动 fork 时出错

Maven Surefire: Error occured in starting fork

当我尝试 运行

mvn test

我总是收到错误消息,指出在 starring fork 中发生了 maven-surefire 错误。这与我的本地设置有关,在我同事的 PC 上它工作正常。我希望有人知道我的电脑出了什么问题:)

错误信息的一部分:

  1. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project exercise00-assignment01: Error occurred in starting fork, check output in log -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project exercise00-assignment01: Error occurred in starting fork, check output in log

  2. Caused by:
        org.apache.maven.surefire.booter.SurefireBooterForkException: Error
        occurred in starting fork, check output in log
            at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork
        (ForkStarter.java:284)
    

我用的是win10,jdk:1.8.0_202,maven:3.6.0

我的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>

    <groupId>at.tuwien.swtesting</groupId>
    <artifactId>exercise00-assignment01</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging> 

    <name>01-RingBufferTest</name>
    <description>Entry exercise.</description>

    <properties>
        <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>junit</groupId>  
            <artifactId>junit</artifactId>  
            <version>4.12</version>  
            <scope>test</scope>  
        </dependency>  
    </dependencies>

</project>

所以我将以下代码添加到我的 pom.xml

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

错误消息已更改:

[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream. [ERROR] Error occurred in starting fork, check output in log [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: Error occurred in starting fork, check output in log [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:623) [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:283) [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:246)

编辑

我终于找到了我的问题,在我的文件夹路径中有一个“&”,windows 无法处理它。这就是出现不同错误消息的原因

我最近陷入了同样的问题。经过大量研究,我的分辨率低于

ForkCount 应设置为“0”

将您的 pom 文件更新为:-

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
        <forkCount>0</forkCount>
        <suiteXmlFiles>`enter code here`
        <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
        </configuration>
    </plugin>
</plugins>

在尝试了许多其他建议后,另一个对我有用的解决方案是为每个测试设置一个分支 class。将 fork 设置为 0 会间歇性地工作,我希望在 运行 和 debug=true 时工作,它们每次都通过(调试中没有 fork)。 3.0.0-M4

surefire forkcount documentation

<plugins>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
         <forkCount>number of test classes</forkCount>
       </configuration>
    </plugin>
</plugins>