与Flyway的集成测试 [英] Integration Testing with Flyway

查看:149
本文介绍了与Flyway的集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Flyway 来处理数据库迁移.一切正常:迁移文件的默认位置为:

I'm using Flyway to handle the database migration. Everything is working fine: the default location of the migration files is:

main/resource/db/migration/V1...

我正在运行集成测试,并且我的设置使用单独的数据库架构进行集成,我也想使用flyway进行管理. 但是,集成测试位于test文件夹(不是main)中.当Flyway bean执行migrate()时,它找不到迁移文件,因为它们位于main文件夹中.如果我将迁移文件放在test/resource/db/migration/V1...中,则可以正常工作.

I am running integration tests and my setup uses an separate database schema for integration, which I would like to manage with flyway as well. The integration tests, though, are located in the test folder (not main). When the Flyway bean executes migrate(), it doesn't find the migration files because they are in the main folder. If I put the migration files in test/resource/db/migration/V1... it works.

我真的不想将这些文件复制到test资源文件夹中,因此不必同时维护这两个文件.有没有一种方法可以强制Flyway使用与普通应用程序相同的迁移文件进行集成测试?

I really don't want to have to copy these file into the test resource folder, so I don't have to maintain both. Is there a way to force Flyway to use the same migration files for the integration test as for the normal app?

推荐答案

我假设您正在使用Maven?对于单元测试,test/resourcesmain/resources都被加载到类路径中. test/resources文件通常优先,因为它们放在类路径中的较高位置(如果我没记错的话).无论如何,我不建议您这样做.

I assume you're using Maven? For unit tests both test/resources and main/resources get loaded into the classpath. test/resources files usually take precedence, as they are placed higher up in the classpath - if I recall correctly. Regardless, I don't recommend you do this.

相反,我建议您对集成测试进行完全不同的Flyway配置,该配置位于单独的目录(即test/resources/integration/migration/)中,并在main/resources/db/migration默认目录之后运行.

Instead I recommend you make an entirely different Flyway configuration for integration testing that is in a separate directory (ie test/resources/integration/migration/) and runs after the main/resources/db/migration default one.

那么,即使不使用Flyway来设置集成数据固定装置,而使用其他一些数据库数据加载工具(如 DbUnit (我确定还有其他).

Even then it might be easier to not use Flyway to setup your integration data fixtures and instead use some other database data loading tools like DbUnit (I'm sure there are others).

这篇关于与Flyway的集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆