2016-04-26 15 views
4

我想用一個繼承自JerseyTest的類來測試我的休息接口。雖然第一個測試方法沒有任何問題,但以下測試失敗,且綁定異常地址已在使用中。我需要在測試之間釋放某種資源才能使其運行?當運行多種方法時,Jersey測試地址已經在使用

class MyClass extends JerseyTest() { 
    @Override 
    protected Application configure() { 
     return new ResourceConfig(MyClass.class); 
    } 
    @Test 
    testFirstThing() { 
     // test some request 
    } 
    @Test 
    testFirstThing() { 
     // test another request 
    } 
} 

回答

4

今天我有同樣的問題,有的通過測試,但有些失敗的BindException

有澤西測試文檔中的解決方案: https://jersey.java.net/documentation/latest/test-framework.html#parallel

有關的目的並行運行多個測試容器,您需要 將TestProperties.CONTAINER_PORT設置爲0值。這將告訴澤西測試框架(和底層測試容器)使用 第一個可用端口。

@Override 
protected Application configure() { 
    forceSet(TestProperties.CONTAINER_PORT, "0"); 
    return new ResourceConfig(MyClass.class); 
} 
+0

非常好,它完美的作品!非常感謝你 ;) – user3774109

相關問題