情況:我有一個MyController類,它與一些外部WebServices一起工作。如何從jUnit測試中啓動maven過濾?
public class MyController {
private String integrationWebServiceURL;
}
這個類的web服務URL在描述符配置控制器豆(的applicationContext.xml)期間傳遞
<bean id="myController" class="com.mypath.MyController">
<property name="integrationWebServiceURL" value="${integration.web.service.url}"/>
</bean>
值是動態的,實際值被存儲在屬性文件中應用。性能
integration.web.service.url=${pom.integration.web.service.url}
但它不是終點 - 真正的VA lue存儲在maven項目文件中(pom.xml),其中filtering = true。
<pom.integration.web.service.url>http://mywebservices.com</pom.integration.web.service.url>
所以,當我們用MVN從pom.xml的安裝測試值複製到適當的application.properties佔位符,然後測試我的類的工作就好了。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/applicationContext.xml"})
public class MyControllerTest {
}
問題:我需要從IDE啓動我的測試,能夠與不同的設置,以發揮和使用IDE的調試功能。但是如果我簡單地從IDE開始這個測試,而沒有初步的Maven構建 - 比我的web服務地址將簡單地從application.properties獲取並且等於「$ {pom.integration.web.service.url}」(例如,Maven過濾的過程不會測試前不工作)。如何調整Maven,Spring或jUnit以從pom.xml中提取我的值?
注意:我知道我可以簡單地在由test-class使用的application.properties或applicationContext.xml文件中明確設置此值,但我需要從pom.xml中提取此值。
如果您使用Eclipse,你嘗試過M2Eclipse或M2E插件嗎? – Ralph
爲什麼你需要從POM中獲得價值?或者說,我的意思是,爲什麼POM是一個適合存儲這些信息的地方?我建議將這些數據保存在可交付工件外側的屬性文件中,並僅在運行時訪問它。然後,您可以獲得屬性文件的一個版本,僅在測試類路徑中提供,該文件特定於測試。 –
@Ralph IntelliJ IDEA是我的IDE。 – dim1902