jfu*_*jfu 5 testing spring surefire maven
在我的spring + maven应用程序中,我已经为数据访问层创建了一些测试,我现在希望针对多个数据源运行.我有类似的东西:
@ContextConfiguration(locations={"file:src/test/resources/testAppConfigMysql.xml"})
public class TestFooDao extends AbstractTransactionalJUnit38SpringContextTests {
public void testFoo(){
...
}
}
Run Code Online (Sandbox Code Playgroud)
它目前的配置位置是硬编码的,因此它只能用于一个数据源.调用测试两次并传递两个不同配置的最佳方法是什么(比如testAppConfigMysql.xml和testMyConfigHsqlDb.xml)?
我已经看到过通过系统属性执行此操作的建议.如何告诉maven使用不同的系统属性值调用两次测试?
我不知道是否有一些性感而花哨的解决方案,也很简单,为此。我只需使用所有测试内容实现基类,然后将其继承到具有不同基于注释的配置的两个类中,如下所示:
@ContextConfiguration(locations={"firstDs.xml"})
public class TestFooDaoUsingFirstDs extends TestFooDao {
}
@ContextConfiguration(locations={"secondDs.xml"})
public class TestFooDaoUsingSecondDs extends TestFooDao {
}
Run Code Online (Sandbox Code Playgroud)
除非您必须以这种方式处理大量不同的数据源,否则这对我来说没问题。
归档时间: |
|
查看次数: |
1473 次 |
最近记录: |