JerseyTest默认端口更改为测试REST WEB服务

问题描述 投票:2回答:3

我做了一个测试用例来测试我的Rest Web服务。但在测试用例中,我看到请求将是jersey测试框架的默认端口,即http://localhost:9998,而我的服务是在http://localhost:8080上注册的。我无法找到如何将其端口更改为8080

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());
    }
java web-services rest java-ee jersey-test-framework
3个回答
4
投票

您可以在运行测试时给出命令行参数,例如:

Maven mvn yourpack.UMServiceTest -Djersey.config.test.container.port=8080

或者在eclipse中你可以在run config'Arguments'选项卡中传递它


2
投票

除了kuhajeyan的回答,还有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>

2
投票

您也可以从JerseyTest的TestProperties更改Systemproperty。

public class UMServiceTest extends JerseyTest
{
    static
    {
        System.setProperty("jersey.config.test.container.port", "0");
    }
...
© www.soinside.com 2019 - 2024. All rights reserved.