JerseyTest默认端口更改为测试REST WEB服务
问题描述:
我做了一个测试用例来测试我的Rest Web Service。但在测试案例中,我看到请求将会发送到球衣测试框架的默认端口http://localhost:9998
,而我的服务在http://localhost:8080
上注册。我无法找到我如何可以改变其端口8080
JerseyTest默认端口更改为测试REST WEB服务
public class UMServiceTest extends JerseyTest {
@Override
public Application configure() {
enable(TestProperties.LOG_TRAFFIC);
enable(TestProperties.DUMP_ENTITY);
return new ResourceConfig(UMService.class);
}
@Test
public void testFetchAll() {
System.out.println(getBaseUri()+"==========");
Response output = target("usermanagement").path("um").path("user").request().get();
assertEquals("should return status 200", 200, output.getStatus());
//assertNotNull("Should return list", output.getEntity());
}
答
当你运行测试,例如你可以给一个命令行参数,
Maven的 mvn yourpack.UMServiceTest -Djersey.config.test.container.port=8080
或在日食中,你可以通过这个在运行配置'参数'选项卡
答
除了ku hajeyan的答案在这里是JerseyTest端口的maven配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
....
<systemProperties>
<property>
<name>jersey.config.test.container.port</name>
<value>4410</value>
</property>
</systemProperties>
</configuration>
</plugin>