加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Maven Failsafe插件:如何使用前后集成测试阶段

发布时间:2020-12-14 05:11:25 所属栏目:Java 来源:网络整理
导读:对于我来说,如何最好地使用Maven Failsafe插件进行集成测试还不是很清楚.我的用例是测试针对本地 MySQL数据库的SQL查询. 我了解数据库应该在预集成测试阶段启动,并在后整合测试期间关闭. 但是如何指定呢?有没有我应该放在我的pom.xml中的命令行?或者我应该
对于我来说,如何最好地使用Maven Failsafe插件进行集成测试还不是很清楚.我的用例是测试针对本地 MySQL数据库的SQL查询.

我了解数据库应该在预集成测试阶段启动,并在后整合测试期间关闭.
但是如何指定呢?有没有我应该放在我的pom.xml中的命令行?或者我应该用特定注释注释的方法?

解决方法

在正常的 built-in maven lifecycles(jar,war …)中,预集成测试和后整合测试测试阶段不限于任何maven插件(即,这些阶段的默认行为是“do nothing”).如果要为集成测试阶段执行的测试设置和填充数据库,则需要将执行该作业的maven插件绑定到这些阶段.

SQL maven plugin在maven构建中执行SQL脚本.将此插件绑定到前/后整合阶段的配置非常简单:

在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>

这应该够了吧.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读