您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源單元測(cè)試工具 > junit
使用Grester簡(jiǎn)化Java應(yīng)用程序的JUnit測(cè)試
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/3/22 14:37:43 ] 推薦標(biāo)簽:

清單 1. 把 Maven 指向包含 Groovy 依賴關(guān)系的遠(yuǎn)程系統(tǒng)庫

               
<settings>
 <profiles>
  <profile>
   <id>repositoryDefinitions</id>
   <repositories>
   .....
   .....
   <!-- You may have other repositories -->
   ....
   ....
   <repository>
    <id>apache-snapshotsv/id>
    <name>Apache Snapshots Repository</name>
    <url>http://people.apache.org/repo/m2-snapshot-repository</url>
    <layout>default</layout>
    <snapshots>
     <enabled>true</enabled>
      <updatePolicy>daily</updatePolicy>
      <checksumPolicy>ignore</checksumPolicy>
    </snapshots>
    <releases>
     <enabled>false</enabled>
    </releases>
   </repository>
   .....
   .....
   </repositories>
   ...
  </profile>
 </profiles>
</settings>


接下來是 Maven 的插件配置,該插件配置將指定 Grester 的 Groovy 插件依賴關(guān)系的系統(tǒng)庫。此插件系統(tǒng)庫配置放在為系統(tǒng)庫聲明的同一個(gè)配置文件 中(例如,名稱 repositoryDefinitions 被用作配置文件的名稱),如下所示:

清單 2. 把 Maven 指向包含 Groovy 插件依賴關(guān)系的遠(yuǎn)程系統(tǒng)庫

               
<settings>
 <profiles>
  <profile>
   <id>repositoryDefinitions</id>
   ....
   ....
   </repositories>
   <pluginRepositories>
   <!-- You may have other plug-in repositories -->
   ....
   ....
    <pluginRepository>
     <id>apache-snapshots</id>
     <name>Apache Snapshots Repository</name>
     <url>http://people.apache.org/repo/m2-snapshot-repository</url>
     <layout>default</layout>
     <snapshots>
      <enabled>true</enabled>
      <updatePolicy>daily</updatePolicy>
      <checksumPolicy>ignore</checksumPolicy>
     </snapshots>
     <releases>
      <enabled>false</enabled>
     </releases>
    </pluginRepository>
    ...
    ...
   </pluginRepositories>
   ...
  </profile>
 </profiles>
</settings>


現(xiàn)在您終于可以構(gòu)建插件直至完成。Grester 要求使用 Maven V2.0.5 或更高版本。如果使用早期版本,則會(huì)在編譯和使用 Groovy-mojo-support 依賴關(guān)系中的功能時(shí)遇到問題。如果 $MAVEN_HOME/bin 目錄是可執(zhí)行文件系統(tǒng)路徑的一部分,則可以從 maven-grester-plugin 目錄(包含 Grester 的 pom.xml 文件的目錄)中執(zhí)行 mvn clean install 命令,如下所示:

圖 4. 從命令行構(gòu)建 Grester

構(gòu)建通常運(yùn)行得很快(少于 20 秒)。圖 5 顯示成功安裝窗口。

圖 5. 在 Maven 的本地系統(tǒng)庫中安裝 Grester

Grester 的 TDD 方法
編寫 Grester 時(shí),我必須在編寫集成測(cè)試時(shí)記住它們適用的操作系統(tǒng)環(huán)境。這變得有點(diǎn)挑戰(zhàn)性,因?yàn)槲覍钠ヅ洳僮飨到y(tǒng)類型的 if . . . else 子句開始,然后根據(jù)類型做出斷言。不久,如果為該平臺(tái)編寫測(cè)試的同時(shí) 又為另一個(gè)平臺(tái)編寫測(cè)試,則可以實(shí)現(xiàn)跨兩個(gè)平臺(tái)的穩(wěn)定的成功構(gòu)建。

上一頁12345下一頁
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd