Hamcrest is a unit test framework, the assert function assertThat of hamcrest is more human readable comparing to the assert function of Junit, therefore, Junit4 has already adopted and integrated the hamcrest framework from version 4.4 on. Please check following screenshot.
創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),增城企業(yè)網(wǎng)站建設(shè),增城品牌網(wǎng)站建設(shè),網(wǎng)站定制,增城網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,增城網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
But Junit4 integrates only the core features of hamcrest, in order to facilitate our test automation work, we should add the hamcrest JAR library with all features into our test project.
- Hamcrest-all-xx.jar : Contains all feature of hamcrest
- Hamcreset-core-xx.jar : Contains core feature of hamcrest
We could download hamcrest by following this link:
http://search.maven.org/#search|ga|1|g%3Aorg.hamcrest
Following description would illustrate how to use hamcrest-all in our test project.
Step 1:Drag&drop the hamcrest-all jar package to the libs(Create one if not exist)folder of the project
Step 2: Import hamcrest modules into test script
- “importstatic org.hamcrest.MatcherAssert.assertThat”:in order to use the function“assertThat”
- “import static org.hamcrest.Matchers.*”:in order to use the matcher of“is”,”notNullValue”,”equalTo” and so on.
Step 3:Use hamcrest feature in our test script
Following are the link on the syntax of asserThat function of hamcrest.
http://langgufu.iteye.com/blog/1893927
-----------------------------------------TheEnd--------------------------------------