您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源單元測(cè)試工具 > junit
JUnit:Hamcrest的使用
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/12/11 17:40:30 ] 推薦標(biāo)簽:junit 單元測(cè)試 軟件測(cè)試

  hamcrest 是一款比較不錯(cuò)的 JUnit 測(cè)試 jar 包,本文介紹 hamcrest 在 Java 語言的使用。
  如果你使用過 eclipse 和 JUnit4 的話,hamcrest 的使用會(huì)讓你如虎添翼。
  1. 下載hamcrest
  連接 Google,搜索 hamcrest 即可。
  下載列表:http://code.google.com/p/hamcrest/downloads/list
  選擇 Full Hamcrest distribution 版本,完整版。如果是在 linux 下面,可以下載tgz格式的。
  win 下面下載 zip 吧。其他系統(tǒng)的可以根據(jù)情況下載。
  2. 解壓縮
  tar   -zxvf   ×××.tgz
  解壓之后,將文件夾放到合適的目錄下面。假設(shè)路徑為 /home/mark/tools/hamcrest-1.2
  3. hamcrest 與 Eclipse
  假設(shè)你已經(jīng)新建一個(gè)測(cè)試項(xiàng)目叫 TestHamcrest,并且已經(jīng)導(dǎo)入了 JUnit4 這個(gè)包。
  如果沒有的話,請(qǐng)參考其他關(guān)于 JUnit 的使用的文章。
  在 Eclipse 中,對(duì)項(xiàng)目 TestHamcrest 右鍵,選擇 Build Path / Add External Archives。
  選擇 /home/mark/tools/hamcrest-1.2 下面的 hamcrest-core-1.2.jar、hamcrest-library-1.2.jar 兩個(gè) jar 文件。
  項(xiàng)目中可以:
  import static org.hamcrest.Matchers.*;
  那么,可以直接使用其中的方法。更多關(guān)于 hamcrest 的使用,請(qǐng)參閱文檔!
  4. 遇到麻煩
  trouble:    SecurityException 異常
  methond:刪除 JUnit 包,然后在 Referenced  Library 中再導(dǎo)入 Junit 包。

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