Maven 验证不会使用故障安全执行 Cucumber-Serenity 集成测试

Maven verify doesn't execute Cucumber-Serenity integration tests with fail-safe

我的项目中有以下 POM。

mvn clean verify -P it

POM:

 <build>
        <pluginManagement>
            <plugins>
              .....
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven-plugin.version}</version>
                    <configuration>
                        <skipTests>false</skipTests>
                        <excludes>
                            <exclude>**/*CucumberTests.java</exclude>
                            <exclude>**/IT*.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>${maven-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>integration-tests</id>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                            <configuration>
                                <skipTests>false</skipTests>
                                <testFailureIgnore>true</testFailureIgnore>
                                <excludes>
                                    <exclude>none</exclude>
                                </excludes>
                                <includes>
                                    <include>**/*CucumberTests.java</include>
                                    <include>**/*IT.java</include>
                                </includes>
                                <systemPropertyVariables>
                                    <it.server.port>${random.http.port}</it.server.port>
                                    <it.jmx.port>${random.jmx.port}</it.jmx.port>
                                </systemPropertyVariables>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.5.9.RELEASE</version>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                            <wait>2000</wait>
                            <!-- Max retry count -->
                            <maxAttempts>180</maxAttempts>
                            <jmxPort>${random.jmx.port}</jmxPort>
                            <arguments>
                                <argument>--server.port=${random.http.port}</argument>
                                <argument>--spring.profiles.active=${spring.profile}</argument>
                            </arguments>
                            <jvmArguments>
                                -Djava.security.egd=file:///dev/urandom
                            </jvmArguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                            <jmxPort>${random.jmx.port}</jmxPort>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
       ...
        </plugin>
        </plugins>
    </build>

测试class:

import org.junit.runner.RunWith;

import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
    plugin = {"pretty"},
    glue = {"my.stepdefinitions"},
    tags = {"@Demo"},
    features = "src/it/resources/features/"
)

public class MicroServiceCucumberTests {
}

路径:src/it/java

基本上它会触发 sure-fire 然后启动应用程序并停留在那里 没有执行 maven-failsafe-plugin:2.21.0:integration-test (integration-tests)

正在使用的版本:

<serenity.plugin.version>2.4.34</serenity.plugin.version>
<serenity.version>2.4.34</serenity.version>
<serenity.cucumber.version>2.4.34</serenity.cucumber.version>
<cucumber.version>6.10.4</cucumber.version>
<maven-plugin.version>3.0.0-M5</maven-plugin.version>
<java.version>1.8</java.version>

在深入研究日志后我注意到,应用程序无法正常启动并卡在下面的日志中

DEBUG] Application argument(s): --server.port=54110 --spring.profiles.active=it
[DEBUG] Connecting to local MBeanServer at port 54111
[DEBUG] Waiting for spring application to start...
[DEBUG] MBean server at port 54111 is not up yet...
[DEBUG] Spring application is not ready yet, waiting 2000ms (attempt 1)
[DEBUG] MBean server at port 54111 is not up yet...
[DEBUG] Spring application is not ready yet, waiting 2000ms (attempt 2)

这个解决方案对我有用

在 POM 的 spring-boot-maven-plugin 中添加下面的内容就可以了。

 <configuration>
     <fork>false</fork>
  </configuration>

然而,相同的代码在 iOS 机器上工作,没有上述修复。进一步仍然不确定是什么导致了 Windows.

中的问题