![](/img/trans.png)
[英]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.