我用迁飞来管理我的Spring MVC应用我的数据库的状态测试之间的数据库。Spring MVC的 - 清洁利用迁飞
我已经在我的servlet上下文XML文件中配置完全相同的their docs
<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
<property name="dataSource" ref="..."/>
...
</bean>
<!-- The rest of the application (incl. Hibernate) -->
<!-- Must be run after Flyway to ensure the database is compatible with the code -->
<bean id="sessionFactory" class="..." depends-on="flyway">
...
</bean>
的建议我想要做的两件事情在我的JUnit测试 -
一次,前所有测试,删除并重新创建数据库并让其重新迁移。这为每个测试套件创建一个干净的数据库。
每次测试之前,清理所有的数据库表。在其他框架(例如RSpec/Rails)中,我通过事务性地运行DB语句来完成此操作,以便在测试结束时回滚。不确定Spring MVC世界中的最佳实践。
我不知道从哪里开始实施上述,所以任何指导表示赞赏。
谢谢!
我发现人工清理迁移最可靠和防弹第一种选择。它解决了如果在每次测试之前数据库没有返回到原始状态,那么测试可能会相互影响的问题。 – alebu