如何修复Maven surefire插件错误[分支过程中存在错误]?

时间:2019-03-26 16:56:44

标签: maven docker maven-surefire-plugin

我试图运行使用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)

任何帮助将不胜感激

4 个答案:

答案 0 :(得分:0)

考虑到您将testng.xml保留在 src / test / resources 下(或提供您正在使用的路径),那么我认为您应该将suiteXmlFile提到为

<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>

答案 1 :(得分:0)

以上异常日志明确指出它无法找到TestRunner类。确保您的TestRunner类在类路径上。

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

答案 2 :(得分:0)

我遇到了类似的问题,并且在使用旧版本的public void Configuration(IAppBuilder app)之后,我的问题解决了。

maven-surefire-plugin

答案 3 :(得分:0)

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

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