【发布时间】:2014-08-30 20:58:30
【问题描述】:
我想在 Maven 中运行集成测试时运行 Flyway 插件。对于集成测试,我使用的是故障安全插件。
首先是否可以定义两次 Flyway 插件?一种用于一般用途(例如,从命令行),另一种用于集成测试?如何在 Flyway 插件中为集成测试定义单独的配置?
【问题讨论】:
我想在 Maven 中运行集成测试时运行 Flyway 插件。对于集成测试,我使用的是故障安全插件。
首先是否可以定义两次 Flyway 插件?一种用于一般用途(例如,从命令行),另一种用于集成测试?如何在 Flyway 插件中为集成测试定义单独的配置?
【问题讨论】:
您可以通过插件的不同执行来实现这一点。每个执行都可以有自己的配置。
【讨论】:
您可以使用不同的配置为 Failsafe 的 pre-integration-test 阶段添加执行,请参阅 Maven Failsafe Plugin:
Maven 生命周期有四个运行集成测试的阶段:
- pre-integration-test 用于设置集成测试环境。
- 用于运行集成测试的集成测试。
- post-integration-test 用于拆除集成测试环境。
- 验证以检查集成测试的结果。
和Guide to Configuring Plug-ins:
使用
标签 您还可以使用标签配置 mojo。这最常用于旨在参与构建生命周期某些阶段的 mojo。
例如:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0.3</version>
<configuration>
<url>jdbc:jtds:sqlserver://myCompany.com/generalDatabase</url>
<user>dbUser</user>
<password>password</password>
<locations>
<location>filesystem:src/main/resources/db/migration</location>
</locations>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.2.7</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<id>integration-test-database-setup</id>
<phase>pre-integration-test</phase>
<goals>
<goal>clean</goal>
<goal>migrate</goal>
</goals>
<configuration>
<url>jdbc:jtds:sqlserver://myCompany.com/testDatabase</url>
<user>dbUser</user>
<password>password</password>
<locations>
<location>filesystem:src/test/resources/db/migration</location>
</locations>
</configuration>
</execution>
</executions>
</plugin>
【讨论】: