【问题标题】:how to fix the maven surefire plugin error [there was error in the forked process]?如何修复maven surefire插件错误[分叉过程中有错误]?
【发布时间】:2019-03-26 16:56:44
【问题描述】:

我正在尝试运行使用 Maven-testNG-cucumber 的示例项目并使用 docker 部署它。这是我的 Dockerfile

FROM    maven:3.6.0-jdk-8
RUN     mkdir /docker
WORKDIR /docker
COPY    pom.xml .
COPY    testng.xml .
COPY    src .
RUN     mvn clean verify 

POM.XML

    <dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm-deps</artifactId>
        <version>1.0.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.2.5</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.8</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>cucumber-reporting</artifactId>
        <version>3.8.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.44.0</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20.1</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>
        <plugin>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>3.8.0</version>
            <executions>
                <execution>
                    <id>execution</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <projectName>Sample</projectName>
                        <outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
                        <cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
                        <buildNumber>1</buildNumber>
                        <parallelTesting>false</parallelTesting>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

当我使用 mvn verify 在本地运行项目时,上述场景完全正常。然后我尝试使用 docker build -t sample . 构建图像。这次我收到以下错误。

 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project Sample: There are test failures.
 [ERROR] Please refer to /docker/target/surefire-reports for the individual test results.

 [ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.

 [ERROR] There was an error in the forked process

 [ERROR] Cannot find class in classpath: TestRunner
 [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process

 [ERROR] Cannot find class in classpath: TestRunner
 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork
 (ForkStarter.java:673)
 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork
 (ForkStarter.java:535)
 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run 
 (ForkStarter.java:280)
 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run
 (ForkStarter.java:245)
 [ERROR] at 
 org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider
 (AbstractSurefireMojo.java:1124)
 [ERROR]         at 
 org.apache.maven.plugin.surefire.AbstractSurefireMojo.
 executeAfterPreconditionsChecked(AbstractSurefireMojo.java:954)

任何帮助将不胜感激

【问题讨论】:

    标签: maven docker maven-surefire-plugin


    【解决方案1】:

    我遇到了类似的问题,在使用旧版本的 maven-surefire-plugin 后解决了我的问题。

           <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <!-- latest version does not work well with JUnit5 -->
                <version>2.19.1</version>
                <dependencies>
                    <dependency>
                        <groupId>org.junit.platform</groupId>
                        <artifactId>junit-platform-surefire-provider</artifactId>
                        <version>1.0.3</version>
                    </dependency>
                    <dependency>
                        <groupId>org.junit.jupiter</groupId>
                        <artifactId>junit-jupiter-engine</artifactId>
                        <version>5.0.3</version>
                    </dependency>
                </dependencies>
            </plugin>
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,但是用不同的解决方案解决了,您也可以检查以下问题。

      实际上,我在 POM.XML 中给出了错误的 testNG.xml 路径,这就是它向我抛出该错误的原因。请交叉验证您的 testNG.xml 路径。

      【讨论】:

        【解决方案3】:

        上面的异常日志明确指出无法找到TestRunner类。确保您的 TestRunner 类位于类路径中。

        由于在 TestNG XML 文件的“类”部分中添加了很少的额外字符,我遇到了类似的异常。值得检查 TestNG XML 文件是否正确,并且不包含任何超出所需结构的额外字符。

        【讨论】:

          【解决方案4】:

          我遇到了同样的问题。它在 maven clean build 后得到解决,然后运行测试。

          【讨论】:

          • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
          【解决方案5】:

          我也遇到了同样的问题,我只是用了 maven 的 clean 命令。

          clean -f pom.xml

          如果您在 IntelliJ 中工作,则可以改用 maven 插件。 在右侧点击 maven Tab -> plugins -> clean -> clean:clean

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2019-08-20
            • 1970-01-01
            • 2018-08-28
            • 2021-04-22
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多