您是否使用 Apache Maven 来运行此类测试?这就是我的做法。在 Maven 方面,我使用 buildhelper 插件和 surefire 来定义随机端口并将其作为系统属性传递给测试
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-network-port</id>
<phase>initialize</phase>
<goals>
<goal>reserve-network-port</goal>
</goals>
<configuration>
<portNames>
<portName>tomcat.http.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<!-- Port used for Tomcat HTTP connector -->
<tomcat.http.port>${tomcat.http.port}</tomcat.http.port>
</systemProperties>
</configuration>
</plugin>
</plugins>
然后我配置了 arquillian
<arquillian>
<container qualifier="tomcat" default="true">
<configuration>
<property name="bindHttpPort">${tomcat.http.port:9090}</property>
</configuration>
</container
</arquillian>
注意:当我从 IDE 启动测试时,我使用端口的默认值以避免手动配置它。
高温高压
干杯,