[英]how to add pre and post integration phase to maven-failsafe-plugin
[英]Maven Failsafe Plugin: how to use the pre- and post-integration-test phases
我不完全清楚如何最好地使用Maven Failsafe插件进行集成测试。 我的用例是针对本地MySQL数据库测试SQL查询。
我知道数据库应该在pre-integration-test
阶段启动,并在post-integration-test
期间关闭。 但是我该如何指定呢? 我应该在我的pom.xml中放一个命令行吗? 或者我应该使用特定注释进行注释的方法?
在常规的内置maven生命周期 (jar,war ......)中, pre-integration-test
和post-integration-test
测试阶段不受任何maven插件的约束(即,这些阶段的默认行为是“什么都不做” “)。 如果要为integration-test
阶段中执行的测试设置和填充数据库,则需要将执行该作业的maven插件绑定到这些阶段。
SQL maven插件在maven构建中执行SQL脚本。 将此插件绑定到pre/post-integration-phase
的配置非常简单:
在pom.xml文件的build
> plugins
部分中,添加sql-maven-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<!-- include the JDBC driver dependency here -->
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
</dependency>
</dependencies>
<!-- common plugin configuration -->
<configuration>
<driver>...</driver>
<url>...</url>
<username>...</username>
<password>...</password>
<!-- other parameters -->
</configuration>
<!-- the executions section binds the phases with some plugin goals and optional additional configuration parameters -->
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<!-- specific configuration for this execution -->
<configuration>
<!-- Include here the SQL scripts to create the DB, inject some test data -->
</configuration>
</execution>
<execution>
<phase>post-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<!-- Include here the SQL scripts to drop the database -->
</configuration>
</execution>
[...]
</executions>
</plugin>
这应该够了吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.