Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Maven Failsafe插件:如何使用集成前和集成后测试阶段_Java_Maven_Integration Testing_Maven Failsafe Plugin - Fatal编程技术网

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

Java Maven Failsafe插件:如何使用集成前和集成后测试阶段,java,maven,integration-testing,maven-failsafe-plugin,Java,Maven,Integration Testing,Maven Failsafe Plugin,我还不完全清楚如何最好地使用Maven Failsafe插件进行集成测试。我的用例是针对本地MySQL数据库测试SQL查询 我知道数据库应该在集成前测试阶段启动,在集成后测试阶段关闭。 但我该如何具体说明呢?是否应该在pom.xml中输入命令行?或者我应该用特定注释注释的方法?在常规(jar,war…)中,集成前测试和集成后测试阶段不绑定到任何maven插件(即,这些阶段的默认行为是“不做任何事情”)。如果您想为集成测试阶段中执行的测试设置和填充数据库,则需要将执行该工作的maven插件绑定到这

我还不完全清楚如何最好地使用Maven Failsafe插件进行集成测试。我的用例是针对本地MySQL数据库测试SQL查询

我知道数据库应该在集成前测试阶段启动,在集成后测试阶段关闭。 但我该如何具体说明呢?是否应该在pom.xml中输入命令行?或者我应该用特定注释注释的方法?

在常规(jar,war…)中,
集成前测试和
集成后测试阶段不绑定到任何maven插件(即,这些阶段的默认行为是“不做任何事情”)。如果您想为
集成测试
阶段中执行的测试设置和填充数据库,则需要将执行该工作的maven插件绑定到这些阶段

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

在pom.xml文件的
build
plugins
部分,添加sql maven插件

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

org.codehaus.mojo
SQLMaven插件
1.5
...
...
...
...
...
...
...
预集成测试
执行
整合后测试
执行
[...]

这应该可以解决问题。

您真的需要MySQL还是使用内存中的数据库来测试查询就足够了?好吧,我想了解如何使用这两个阶段。所以,一个关于内存中MySQL数据库的解决方案会很有趣,但我对这两个阶段的细节更感兴趣(我已经知道H2在MySQL模式下的使用。我发现的唯一一个真正的内存中MySQL数据库自2006年以来没有更新过…)太好了,它看起来正是我需要的。但是没有办法启动MySQL实例?您可以使用exec插件启动MySQL实例:我建议使用以下插件:。