随笔-112  评论-73  文章-0  trackbacks-0

以前一直是在pom.xml文件中调用ant 来执行dbunit,这样有一个弊端就是ant 中的变量和pom中的变量不能很好的共享。

今天发现一个m2 的插件,就是 DbUnit Maven Plugin 。这个插件的使用方法也很简单,主页上就有例子。

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>dbunit-maven-plugin</artifactId>

<!--jar file that has the jdbc driver -->

<dependencies>

<!-- 是连接数据的jar包-->

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.6</version>

</dependency>

</dependencies>



<!-- common configurations -->



<!-- 连接数据库的URL等信息-->

<configuration>

<driver>com.mysql.jdbc.Driver</driver>

<url>jdbc:mysql://localhost:3306/xiangyun</url>

                    
<username>xiangyun</username>

<password>xiangyun</password>

</configuration>

<executions>

<execution>



<!-- 执行的阶段 这个是在编译测试文件时执行-->

<phase>test-compile</phase>

<goals>

<goal>operation</goal>

</goals>

<configuration>

<type>CLEAN_INSERT</type>



<!-- 执行的文件的位置 同以前使用的dbunit 文件一样-->

<src>src/test/resources/initData.xml</src>

</configuration>

</execution>

</executions>

</plugin>
这样就会在执行编译测试文件时执行DBunit的CLEAN_INSERT操作了。

同时使用多个<src>filename</src>不好用,每个<execution>只能使用一个<src></src>,就是只能使用一个文件。
posted on 2008-12-03 17:07 Libo 阅读(1476) 评论(0)  编辑  收藏 所属分类: maven

只有注册用户登录后才能发表评论。


网站导航: