以前一直是在pom.xml文件中調(diào)用ant 來(lái)執(zhí)行dbunit,這樣有一個(gè)弊端就是ant 中的變量和pom中的變量不能很好的共享。
今天發(fā)現(xiàn)一個(gè)m2 的插件,就是 DbUnit Maven Plugin 。這個(gè)插件的使用方法也很簡(jiǎn)單,主頁(yè)上就有例子。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dbunit-maven-plugin</artifactId>
<!--jar file that has the jdbc driver -->
<dependencies>
<!-- 是連接數(shù)據(jù)的jar包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<!-- common configurations -->
<!-- 連接數(shù)據(jù)庫(kù)的URL等信息-->
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/xiangyun</url>
<username>xiangyun</username>
<password>xiangyun</password>
</configuration>
<executions>
<execution>
<!-- 執(zhí)行的階段 這個(gè)是在編譯測(cè)試文件時(shí)執(zhí)行-->
<phase>test-compile</phase>
<goals>
<goal>operation</goal>
</goals>
<configuration>
<type>CLEAN_INSERT</type>
<!-- 執(zhí)行的文件的位置 同以前使用的dbunit 文件一樣-->
<src>src/test/resources/initData.xml</src>
</configuration>
</execution>
</executions>
</plugin>
這樣就會(huì)在執(zhí)行編譯測(cè)試文件時(shí)執(zhí)行DBunit的CLEAN_INSERT操作了。
同時(shí)使用多個(gè)<src>filename</src>不好用,每個(gè)<execution>只能使用一個(gè)<src></src>,就是只能使用一個(gè)文件。
posted on 2008-12-03 17:07
Libo 閱讀(1491)
評(píng)論(0) 編輯 收藏 所屬分類:
maven