情况:我有一个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