Ответ 1
В регулярном встроенных жизненных циклах maven (jar, war...) фазы тестирования pre-integration-test
и post-integration-test
не являются связанный с любым плагином maven (т.е. поведение по умолчанию этих фаз "ничего не делает" ). Если вы хотите настроить и заполнить базу данных для тестов, выполненных в фазе integration-test
, вам необходимо привязать плагин maven, выполнив это задание к этим этапам.
Плагин SQL maven выполняет SQL script в maven-сборке. Конфигурация для привязки этого плагина к pre/post-integration-phase
довольно проста:
В разделе build
> plugins
файла pom.xml добавьте 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>
Это должно сделать трюк.