如何在Spring

时间:2016-04-07 08:47:58

标签: java spring junit spring-test dbunit

我在 Spring 的测试用例中使用 DBUnit ,通过扩展类 DBTestCase < / strong>在我的测试类中使用&#39; SpringJUnit4ClassRunner &#39;。

运行

事情很好,但是在我的实际应用程序中,表分散在几个 DB Schemas 中,所以我有几个 数据源 bean在我的 Spring Content XML 中定义。

因此,在设置 DBUnit 时,我们需要覆盖方法 newDatabaseTester ,以便为其提供 IDatabaseTester 实例,同时创建&#39; DataSourceDatabaseTester &#39; bean只在构造函数中使用单个数据源。

有没有人知道在这种情况下设置 DBUnit 的正确方法,还是有一些我可以访问的示例项目实现了这个?谢谢!!

1 个答案:

答案 0 :(得分:0)

您可以查看https://github.com/springtestdbunit/spring-test-dbunit#working-with-multiple-connections此库有助于简单配置DBUnit测试,并提供将数据集导入不同的数据源。