簡體   English   中英

Maven Failsafe插件:如何使用集成前和集成后測試階段

[英]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-testpost-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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM